Skip to content

Commit

Permalink
Access to dynamic Reusable part. (#4192)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtkech authored and sebastienros committed Sep 9, 2019
1 parent fa80671 commit 74830db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
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");

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 All @@ -143,7 +156,6 @@ public async Task BuildDisplayAsync(ContentItem contentItem, BuildDisplayContext
}

context = tempContext;

}
}
}
Expand Down
Expand Up @@ -64,7 +64,7 @@ public ShapeTable GetShapeTable(string themeId)

foreach (var bindingStrategy in _bindingStrategies)
{
IFeatureInfo strategyFeature = _typeFeatureProvider.GetFeatureForDependency(bindingStrategy.GetType());
var strategyFeature = _typeFeatureProvider.GetFeatureForDependency(bindingStrategy.GetType());

if (!(bindingStrategy is IShapeTableHarvester) && excludedFeatures.Contains(strategyFeature.Id))
continue;
Expand Down

0 comments on commit 74830db

Please sign in to comment.