OrchardCore
OrchardCore copied to clipboard
Remove Content.Edit Part Shape Not Working
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".
In the meantime you might be able to use placement. But it might have the same issue.
Probably edit shapes don't have names by design, as I didn't see why anyone would do that ;)
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.