in src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeResult.cs [53:205]
private async Task ApplyImplementationAsync(BuildShapeContext context, string displayType)
{
// If no location is set from the driver, use the one from the context
if (String.IsNullOrEmpty(_defaultLocation))
{
_defaultLocation = context.DefaultZone;
}
// Look into specific implementations of placements (like placement.json files and IShapePlacementProviders)
var placement = context.FindPlacement(_shapeType, _differentiator, displayType, context);
// Look for mapped display type locations
if (_otherLocations != null)
{
string displayTypePlacement;
if (_otherLocations.TryGetValue(displayType, out displayTypePlacement))
{
_defaultLocation = displayTypePlacement;
}
}
// If no placement is found, use the default location
if (placement == null)
{
placement = new PlacementInfo() { Location = _defaultLocation };
}
if (placement.Location == null)
{
// If a placement was found without actual location, use the default.
// It can happen when just setting alternates or wrappers for instance.
placement.Location = _defaultLocation;
}
if (placement.DefaultPosition == null)
{
placement.DefaultPosition = context.DefaultPosition;
}
// If there are no placement or it's explicitly noop then stop rendering execution
if (String.IsNullOrEmpty(placement.Location) || placement.Location == "-")
{
return;
}
// Parse group placement.
_groupId = placement.GetGroup() ?? _groupId;
// If the shape's group doesn't match the currently rendered one, return
if (!String.Equals(context.GroupId ?? "", _groupId ?? "", StringComparison.OrdinalIgnoreCase))
{
return;
}
var newShape = Shape = await _shapeBuilder(context);
// Ignore it if the driver returned a null shape.
if (newShape == null)
{
return;
}
var newShapeMetadata = newShape.Metadata;
newShapeMetadata.Prefix = _prefix;
newShapeMetadata.Name = _name ?? _differentiator ?? _shapeType;
newShapeMetadata.Differentiator = _differentiator ?? _shapeType;
newShapeMetadata.DisplayType = displayType;
newShapeMetadata.PlacementSource = placement.Source;
newShapeMetadata.Tab = placement.GetTab();
newShapeMetadata.Card = placement.GetCard();
newShapeMetadata.Column = placement.GetColumn();
newShapeMetadata.Type = _shapeType;
if (_displaying != null)
{
newShapeMetadata.OnDisplaying(_displaying);
}
// The _processing callback is used to delay execution of costly initialization
// that can be prevented by caching
if (_processing != null)
{
newShapeMetadata.OnProcessing(_processing);
}
// Apply cache settings
if (!String.IsNullOrEmpty(_cacheId) && _cache != null)
{
_cache(newShapeMetadata.Cache(_cacheId));
}
// If a specific shape is provided, remove all previous alternates and wrappers.
if (!String.IsNullOrEmpty(placement.ShapeType))
{
newShapeMetadata.Type = placement.ShapeType;
newShapeMetadata.Alternates.Clear();
newShapeMetadata.Wrappers.Clear();
}
if (placement != null)
{
if (placement.Alternates != null)
{
newShapeMetadata.Alternates.AddRange(placement.Alternates);
}
if (placement.Wrappers != null)
{
newShapeMetadata.Wrappers.AddRange(placement.Wrappers);
}
}
dynamic parentShape = context.Shape;
if (placement.IsLayoutZone())
{
parentShape = context.Layout;
}
var position = placement.GetPosition();
var zones = placement.GetZones();
foreach (var zone in zones)
{
if (parentShape == null)
{
break;
}
var zoneProperty = parentShape.Zones;
if (zoneProperty != null)
{
// parentShape is a ZoneHolding
parentShape = zoneProperty[zone];
}
else
{
// try to access it as a member
parentShape = parentShape[zone];
}
}
position = !String.IsNullOrEmpty(position) ? position : null;
if (parentShape is ZoneOnDemand zoneOnDemand)
{
await zoneOnDemand.AddAsync(newShape, position);
}
else if (parentShape is Shape shape)
{
shape.Add(newShape, position);
}
}