OrchardCore icon indicating copy to clipboard operation
OrchardCore copied to clipboard

Remove Content.Edit Part Shape Not Working

Open jeffolmstead opened this issue 6 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

In the meantime you might be able to use placement. But it might have the same issue.

sebastienros avatar Feb 21 '19 21:02 sebastienros

Probably edit shapes don't have names by design, as I didn't see why anyone would do that ;)

sebastienros avatar Feb 21 '19 21:02 sebastienros

It is amazing all the things I end up wanting to do with Orchard :) For the interim, I am rendering every shape by hand (that I want to render) and then not using

@await DisplayAsync(Model.Parts)

If a new shape is added though, it wouldn't be rendered unless I edit the template.

jeffolmstead avatar Feb 22 '19 09:02 jeffolmstead