Skip to content

Add explicit model types to Content/Part editor views#19305

Open
okalangkenneth wants to merge 5 commits into
OrchardCMS:mainfrom
okalangkenneth:feature/content-part-viewmodels-19273
Open

Add explicit model types to Content/Part editor views#19305
okalangkenneth wants to merge 5 commits into
OrchardCMS:mainfrom
okalangkenneth:feature/content-part-viewmodels-19273

Conversation

@okalangkenneth

Copy link
Copy Markdown
Contributor

Closes #19273

Introduces a strongly-typed ContentPartShapeViewModel for the ContentPart_Edit
editor shape and adds explicit @model directives to the remaining Content/Part
views in OrchardCore.Contents, continuing the pattern established in #18641.

Changes

  • ContentPartShapeViewModel: new class in OrchardCore.ContentManagement.Display/ViewModels/,
    extending ShapeViewModel with typed ContentPart and ContentTypePartDefinition properties
  • ContentItemDisplayCoordinator : CreateShapeResult() now instantiates
    ContentPartShapeViewModel directly; BuildEditorAsync and UpdateEditorAsync
    assign typed properties instead of Properties[...] dictionary entries. A fallback
    else branch preserves the old Properties[...] assignment for any code path that
    produces a non-ContentPartShapeViewModel shape
  • ContentPart.Edit.cshtml : @model ContentPartShapeViewModel added; all member
    access is now statically typed
  • ContentItem.cshtml : @model IShape added (Items is declared on IShape)
  • Stereotype.Edit.cshtml, Stereotype.DetailAdmin.cshtml, Stereotype.Summary.cshtml,
    Stereotype.SummaryAdmin.cshtml: @model IShape added

Notes

  • Shape type registration is unaffected: ShapeResult.BuildAndAddShapeAsync always
    sets Metadata.Type from the shape type string, regardless of how the factory creates
    the shape
  • The display-path ContentPart.cshtml variants (and Content.cshtml) are not included
    here, those shapes are ZoneHolding instances, and the zone surface requires a
    separate approach; deferred as a follow-up


namespace OrchardCore.ContentManagement.Display.ViewModels;

public class ContentPartShapeViewModel : ShapeViewModel

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ShapeResult is expecting this to be a Shape instance, otherwise the editors are not added to the parentShape here:

if (parentShape is Shape shape)
{
await shape.AddAsync(newShape, position);
}

I'm not sure if that's a bug in ShapeResult or by design.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a real regression. ShapeViewModel doesn't inherit Shape so the is Shape check at ShapeResult.cs:473 would silently discard child shapes when ContentPartShapeViewModel is the terminal parent in zone traversal. I have fixed it by replacing the guard with a null-check....parentShape is typed IShape at that point and IShape contracts AddAsync so no cast is needed.

@okalangkenneth okalangkenneth force-pushed the feature/content-part-viewmodels-19273 branch from 5dfbd43 to 8421ce7 Compare June 3, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Content/Part view models with explicit model type

2 participants