Skip to content

Commit

Permalink
Add fallback alternate when a custom stereotype is used (#12149)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Aug 18, 2022
1 parent 03d0534 commit 12be745
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@{
Model.Metadata.Type = "Content_DetailAdmin";
Model.Metadata.Alternates.Clear();
@await DisplayAsync(Model)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@{
Model.Metadata.Type = "Content_Edit";
Model.Metadata.Alternates.Clear();
@await DisplayAsync(Model)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@{
Model.Metadata.Type = "Content_Summary";
Model.Metadata.Alternates.Clear();
@await DisplayAsync(Model)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@{
Model.Metadata.Type = "Content_SummaryAdmin";
Model.Metadata.Alternates.Clear();
@await DisplayAsync(Model)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@{
Model.Metadata.Type = "Content";
Model.Metadata.Alternates.Clear();
@await DisplayAsync(Model)
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,17 @@ public async Task<IShape> BuildDisplayAsync(ContentItem contentItem, IUpdateMode
}

var stereotype = contentTypeDefinition.GetSettings<ContentTypeSettings>().Stereotype;
var actualDisplayType = string.IsNullOrEmpty(displayType) ? "Detail" : displayType;
var actualShapeType = stereotype ?? "Content";
var actualDisplayType = String.IsNullOrEmpty(displayType) ? "Detail" : displayType;
var hasStereotype = !String.IsNullOrWhiteSpace(stereotype);

// _[DisplayType] is only added for the ones different than Detail
var actualShapeType = "Content";

if (hasStereotype)
{
actualShapeType = stereotype;
}

// [DisplayType] is only added for the ones different than Detail
if (actualDisplayType != "Detail")
{
actualShapeType = actualShapeType + "_" + actualDisplayType;
Expand All @@ -80,7 +87,27 @@ public async Task<IShape> BuildDisplayAsync(ContentItem contentItem, IUpdateMode
var metadata = itemShape.Metadata;
metadata.DisplayType = actualDisplayType;

// [Stereotype]_[DisplayType]__[ContentType] e.g. Content-BlogPost.Summary
if (hasStereotype)
{
if (actualDisplayType != "Detail")
{
// Add fallback/default alternate Stereotype_[DisplayType] e.g. Content.Summary
metadata.Alternates.Add($"Stereotype_{actualDisplayType}");

// [Stereotype]_[DisplayType] e.g. Menu.Summary
metadata.Alternates.Add($"{stereotype}_{actualDisplayType}");
}
else
{
// Add fallback/default alternate i.e. Content
metadata.Alternates.Add("Stereotype");

// Add alternate to make the type [Stereotype] e.g. Menu
metadata.Alternates.Add(stereotype);
}
}

// Add alternate for [Stereotype]_[DisplayType]__[ContentType] e.g. Content-BlogPost.Summary
metadata.Alternates.Add($"{actualShapeType}__{contentItem.ContentType}");

var context = new BuildDisplayContext(
Expand Down Expand Up @@ -114,14 +141,28 @@ public async Task<IShape> BuildEditorAsync(ContentItem contentItem, IUpdateModel
}

var stereotype = contentTypeDefinition.GetSettings<ContentTypeSettings>().Stereotype;
var hasStereotype = !String.IsNullOrWhiteSpace(stereotype);
var actualShapeType = "Content_Edit";

var actualShapeType = (stereotype ?? "Content") + "_Edit";
if (hasStereotype)
{
actualShapeType = stereotype + "_Edit";
}

var itemShape = await CreateContentShapeAsync(actualShapeType);
itemShape.Properties["ContentItem"] = contentItem;
itemShape.Properties["Stereotype"] = stereotype;

// adding an alternate for [Stereotype]_Edit__[ContentType] e.g. Content-Menu.Edit
if (hasStereotype)
{
// Add fallback/default alternate for Stereotype_Edit e.g. Stereotype.Edit
itemShape.Metadata.Alternates.Add("Stereotype_Edit");

// add [Stereotype]_Edit e.g. Menu.Edit
itemShape.Metadata.Alternates.Add(actualShapeType);
}

// Add an alternate for [Stereotype]_Edit__[ContentType] e.g. Content-Menu.Edit
itemShape.Metadata.Alternates.Add(actualShapeType + "__" + contentItem.ContentType);

var context = new BuildEditorContext(
Expand Down Expand Up @@ -156,13 +197,28 @@ public async Task<IShape> UpdateEditorAsync(ContentItem contentItem, IUpdateMode
}

var stereotype = contentTypeDefinition.GetSettings<ContentTypeSettings>().Stereotype;
var actualShapeType = (stereotype ?? "Content") + "_Edit";
var hasStereotype = !String.IsNullOrWhiteSpace(stereotype);
var actualShapeType = "Content_Edit";

if (hasStereotype)
{
actualShapeType = stereotype + "_Edit";
}

var itemShape = await CreateContentShapeAsync(actualShapeType);
itemShape.Properties["ContentItem"] = contentItem;
itemShape.Properties["Stereotype"] = stereotype;

// adding an alternate for [Stereotype]_Edit__[ContentType] e.g. Content-Menu.Edit
if (hasStereotype)
{
// Add fallback/default alternate for Stereotype_Edit e.g. Stereotype.Edit
itemShape.Metadata.Alternates.Add("Stereotype_Edit");

// add [Stereotype]_Edit e.g. Menu.Edit
itemShape.Metadata.Alternates.Add(actualShapeType);
}

// Add an alternate for [Stereotype]_Edit__[ContentType] e.g. Content-Menu.Edit
itemShape.Metadata.Alternates.Add(actualShapeType + "__" + contentItem.ContentType);

var context = new UpdateEditorContext(
Expand Down

0 comments on commit 12be745

Please sign in to comment.