Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to dynamic Reusable part. #4192

Merged
merged 3 commits into from Sep 9, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -70,6 +70,7 @@ public async Task BuildDisplayAsync(ContentItem contentItem, BuildDisplayContext
{
var partName = contentTypePartDefinition.Name;
var partTypeName = contentTypePartDefinition.PartDefinition.Name;
var contentType = contentTypePartDefinition.ContentTypeDefinition.Name;
var partActivator = _contentPartFactory.GetTypeActivator(partTypeName);
var part = contentItem.Get(partActivator.Type, partName) as ContentPart;

Expand All @@ -96,12 +97,12 @@ public async Task BuildDisplayAsync(ContentItem contentItem, BuildDisplayContext
// Create a custom ContentPart shape that will hold the fields for dynamic content part (not implicit parts)
// This allows its fields to be grouped and templated

if (part.GetType() == typeof(ContentPart) && contentTypePartDefinition.PartDefinition.Name != contentTypePartDefinition.ContentTypeDefinition.Name)
if (part.GetType() == typeof(ContentPart) && partTypeName != contentTypePartDefinition.ContentTypeDefinition.Name)
{
var shapeType = context.DisplayType != "Detail" ? "ContentPart_" + context.DisplayType : "ContentPart";

var shapeResult = new ShapeResult(shapeType, ctx => ctx.ShapeFactory.CreateAsync(shapeType, () => Task.FromResult<IShape>(new ZoneHolding(() => ctx.ShapeFactory.CreateAsync("Zone", Arguments.Empty)))));
shapeResult.Differentiator(contentTypePartDefinition.PartDefinition.Name);
shapeResult.Differentiator(partName);
shapeResult.Location("Content");

Copy link
Member

Choose a reason for hiding this comment

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

Looks good @jtkech
For info @jptissot this shapeResult.Location("Content"); is why it's also showing up in SummaryAdmin - this will make it show everywhere, always. For laters when we know what is the best idea for hiding this, we could do another pr to match whatever is decided.

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean we should do a shapeResult.Location("DetailsAdmin", "-"); too here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that's ok here, a dynamic part is composed of fields, so the rendering depends on the field drivers where most of them are not rendered in SummaryAdmin.

E.g if a blog post has a dyn part, when displaying the blog in DetailAdmin, the related list part will be rendered in DetailAdmin but each blogpost will be rendered in SummaryAdmin.

The "problem" is when the blog itself has an additional field / part (dynamic or not), it will be rendered when displaying the blog in DetailAdmin. But i think that there is nothing to do here, this seems to be only due to the field drivers.

Most of the field drivers already do

.Location("SummaryAdmin", "")

Maybe we could add

.Location("DetailAdmin", "")

await shapeResult.ApplyAsync(context);
Expand All @@ -110,14 +111,26 @@ public async Task BuildDisplayAsync(ContentItem contentItem, BuildDisplayContext

// Make the ContentPart name property available on the shape
dynamic dynamicContentPartShape = contentPartShape;
dynamicContentPartShape[contentTypePartDefinition.PartDefinition.Name] = part.Content;
dynamicContentPartShape[partTypeName] = part.Content;
dynamicContentPartShape["ContentItem"] = part.ContentItem;

contentPartShape.Metadata.Alternates.Add(contentTypePartDefinition.PartDefinition.Name);
contentPartShape.Metadata.Alternates.Add(partTypeName);
contentPartShape.Metadata.Alternates.Add($"{contentType}__{partTypeName}");

if (context.DisplayType != "Detail")
{
contentPartShape.Metadata.Alternates.Add($"{contentTypePartDefinition.PartDefinition.Name}_{context.DisplayType}");
contentPartShape.Metadata.Alternates.Add($"{partTypeName}_{context.DisplayType}");
contentPartShape.Metadata.Alternates.Add($"{contentType}_{context.DisplayType}__{partTypeName}");
}

if (partName != partTypeName)
{
contentPartShape.Metadata.Alternates.Add($"{contentType}__{partName}");

if (context.DisplayType != "Detail")
{
contentPartShape.Metadata.Alternates.Add($"{contentType}_{context.DisplayType}__{partName}");
}
}

context = new BuildDisplayContext(shapeResult.Shape, context.DisplayType, context.GroupId, context.ShapeFactory, context.Layout, context.Updater);
Expand Down