OrchardCore icon indicating copy to clipboard operation
OrchardCore copied to clipboard

Remove Content.Edit Part Shape Not Working

Open jeffolmstead opened this issue 5 years ago • 3 comments

I have modified "Content.Edit" with an override in order to be able to remove some shapes but the shapes are not removed. Here is the code snipped:

// Add in alternates
Model.Parts["AccountAddressPart"].Metadata.Alternates.Add("AccountAddressPart_Edit");
Model.Parts["AccountContactPart"].Metadata.Alternates.Add("AccountContactPart_Edit");

// Store shapes for later rendering
var accountAddressPartShape = Model.Parts["AccountAddressPart"];
var accountContactPartShape = Model.Parts["AccountContactPart"];

// Remove shapes from rendering
Model.Parts.Remove("AccountAddressPart");
Model.Parts.Remove("AccountContactPart");

@await DisplayAsync(Model.Parts)

// Render the specific shapes
<div class="row">
    <div class="col-sm-6">
        @await DisplayAsync(accountAddressPartShape)
    </div>
    <div class="col-sm-6">
        @await DisplayAsync(accountContactPartShape)
    </div>
</div>

But the AddressPartShape and the ContactPartShape are rendered twice as they are not removed. I looked in the base code for this and on OrchardCore.DisplayManagement.Shapes.Shape Remove method it uses the passed in string to find the item where the shape.Metadata.Name is equal to the passed in string. This seems to be the issue as all the shapes under Model.Parts do NOT have a name associated with them (i.e. if you explore there Metadata the Name field is always null). I believe this is why there are also no shape alternates available by default for editing.

This may be just an issue on the "Edit" side of things, I did not check for the same issue in "Detail" or "Summary".

jeffolmstead avatar Feb 16 '19 15:02 jeffolmstead