forked from OrchardCMS/OrchardCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Widget alternates for alias and slug (OrchardCMS#16860)
--------- Co-authored-by: Mike Alhayek <[email protected]>
- Loading branch information
1 parent
ec2b767
commit 978d426
Showing
8 changed files
with
148 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/OrchardCore.Modules/OrchardCore.Alias/Services/WidgetAliasShapeTableProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using OrchardCore.Alias.Models; | ||
using OrchardCore.ContentManagement; | ||
using OrchardCore.DisplayManagement; | ||
using OrchardCore.DisplayManagement.Descriptors; | ||
using OrchardCore.DisplayManagement.Utilities; | ||
|
||
namespace OrchardCore.Alias.Services; | ||
|
||
public sealed class WidgetAliasShapeTableProvider : ShapeTableProvider | ||
{ | ||
public override ValueTask DiscoverAsync(ShapeTableBuilder builder) | ||
{ | ||
builder.Describe("Widget") | ||
.OnDisplaying(displaying => | ||
{ | ||
var shape = displaying.Shape; | ||
var contentItem = shape.GetProperty<ContentItem>("ContentItem"); | ||
var aliasPart = contentItem?.As<AliasPart>(); | ||
if (aliasPart != null) | ||
{ | ||
var encodedAlias = aliasPart.Alias.EncodeAlternateElement(); | ||
// Widget__Alias__[Alias] e.g. Widget-Alias-example, Widget-Alias-my-page | ||
displaying.Shape.Metadata.Alternates.Add("Widget__Alias__" + encodedAlias); | ||
// Widget_[DisplayType]__Alias__[Alias] e.g. Widget-Alias-example.Summary, Widget-Alias-my-page.Summary | ||
displaying.Shape.Metadata.Alternates.Add("Widget_" + displaying.Shape.Metadata.DisplayType + "__Alias__" + encodedAlias); | ||
} | ||
}); | ||
|
||
return ValueTask.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/OrchardCore.Modules/OrchardCore.Autoroute/Services/WidgetAutorouteShapeTableProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using OrchardCore.Autoroute.Models; | ||
using OrchardCore.ContentManagement; | ||
using OrchardCore.DisplayManagement; | ||
using OrchardCore.DisplayManagement.Descriptors; | ||
using OrchardCore.DisplayManagement.Utilities; | ||
|
||
namespace OrchardCore.Autoroute.Services; | ||
|
||
public sealed class WidgetAutorouteShapeTableProvider : ShapeTableProvider | ||
{ | ||
public override ValueTask DiscoverAsync(ShapeTableBuilder builder) | ||
{ | ||
builder.Describe("Widget") | ||
.OnDisplaying(displaying => | ||
{ | ||
var shape = displaying.Shape; | ||
var contentItem = shape.GetProperty<ContentItem>("ContentItem"); | ||
var autoroutePart = contentItem?.As<AutoroutePart>(); | ||
if (autoroutePart != null) | ||
{ | ||
var encodedSlug = autoroutePart.Path.EncodeAlternateElement().Replace("/", "__"); | ||
// Widget__Slug__[Slug] e.g. Widget-Slug-example, Widget-Slug-blog-my-post | ||
displaying.Shape.Metadata.Alternates.Add("Widget__Slug__" + encodedSlug); | ||
// Widget_[DisplayType]__Slug__[Slug] e.g. Widget-Slug-example.Summary, Widget-Slug-blog-my-post.Summary | ||
displaying.Shape.Metadata.Alternates.Add("Widget_" + displaying.Shape.Metadata.DisplayType + "__Slug__" + encodedSlug); | ||
} | ||
}); | ||
|
||
return ValueTask.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters