Skip to content

Commit

Permalink
specify LayerMetadata as prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed Dec 3, 2024
1 parent a555f74 commit 95e558c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ public override async Task<IDisplayResult> EditAsync(ContentItem model, BuildEdi
if (!model.TryGet<LayerMetadata>(out var layerMetadata))
{
layerMetadata = new LayerMetadata();

// In the initial request, the 'Zone' and 'Position' are passed as route values.
// We attempt to populate the new 'LayerMetadata' and ensure the 'Zone' is correctly set.
await context.Updater.TryUpdateModelAsync(layerMetadata, string.Empty, m => m.Zone, m => m.Position);

// Are we loading an editor that requires layer metadata?
if (string.IsNullOrEmpty(layerMetadata.Zone))
{
// At this point, the 'Zone' value was not provided in the route values, so the widget is not visible.
return null;
}

Expand All @@ -50,8 +53,16 @@ public override async Task<IDisplayResult> EditAsync(ContentItem model, BuildEdi
m.Layer = layerMetadata.Layer;
m.Layers = (await _layerService.GetLayersAsync()).Layers
.Select(x => new SelectListItem(x.Name, x.Name));
})
.Location("Content:before");
}).Location("Content:before");
}

protected override void BuildPrefix(ContentItem model, string htmlFieldPrefix)
{
base.BuildPrefix(model, htmlFieldPrefix);
if (string.IsNullOrWhiteSpace(htmlFieldPrefix))
{
Prefix = nameof(LayerMetadata);
}
}

public override async Task<IDisplayResult> UpdateAsync(ContentItem model, UpdateEditorContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@
{
"ContentItemId": "[js: uuid()]",
"ContentType": "RawHtml",
"Displaytext": "Footer",
"DisplayText": "Footer",
"Latest": true,
"Published": true,
"Owner": "[js: parameters('AdminUserId')]",
Expand Down

0 comments on commit 95e558c

Please sign in to comment.