Skip to content

Commit

Permalink
widget alternates dependent on orchardcore.widgets module
Browse files Browse the repository at this point in the history
  • Loading branch information
giannik committed Oct 12, 2024
1 parent 03f87f9 commit 8ff5129
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 82 deletions.

This file was deleted.

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 class ContentAliasShapeTableProvider : ShapeTableProvider
{
public override ValueTask DiscoverAsync(ShapeTableBuilder builder)
{
builder.Describe("Content")
.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();
// Content__Alias__[Alias] e.g. Content-Alias-example, Content-Alias-my-page
displaying.Shape.Metadata.Alternates.Add("Content__Alias__" + encodedAlias);
// Content_[DisplayType]__Alias__[Alias] e.g. Content-Alias-example.Summary, Content-Alias-my-page.Summary
displaying.Shape.Metadata.Alternates.Add("Content_" + displaying.Shape.Metadata.DisplayType + "__Alias__" + encodedAlias);
}
});

return ValueTask.CompletedTask;
}
}
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 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, Content-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;
}
}
11 changes: 10 additions & 1 deletion src/OrchardCore.Modules/OrchardCore.Alias/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IContentPartIndexHandler, AliasPartIndexHandler>();
services.AddScoped<IContentTypePartDefinitionDisplayDriver, AliasPartSettingsDisplayDriver>();

services.AddScoped<IShapeTableProvider, AliasShapeTableProvider>();
services.AddScoped<IShapeTableProvider, ContentAliasShapeTableProvider>();
}
}

[RequireFeatures("OrchardCore.Widgets")]
public sealed class WidgetAliasStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IShapeTableProvider, WidgetAliasShapeTableProvider>();
}
}

This file was deleted.

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 class ContentAutorouteShapeTableProvider : ShapeTableProvider
{
public override ValueTask DiscoverAsync(ShapeTableBuilder builder)
{
builder.Describe("Content")
.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("/", "__");
// Content__Slug__[Slug] e.g. Content-Slug-example, Content-Slug-blog-my-post
displaying.Shape.Metadata.Alternates.Add("Content__Slug__" + encodedSlug);
// Content_[DisplayType]__Slug__[Slug] e.g. Content-Slug-example.Summary, Content-Slug-blog-my-post.Summary
displaying.Shape.Metadata.Alternates.Add("Content_" + displaying.Shape.Metadata.DisplayType + "__Slug__" + encodedSlug);
}
});

return ValueTask.CompletedTask;
}
}
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 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;
}
}
11 changes: 10 additions & 1 deletion src/OrchardCore.Modules/OrchardCore.Autoroute/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddSingleton<AutorouteTransformer>();
services.AddSingleton<IShellRouteValuesAddressScheme, AutorouteValuesAddressScheme>();

services.AddScoped<IShapeTableProvider, AutorouteShapeTableProvider>();
services.AddScoped<IShapeTableProvider, ContentAutorouteShapeTableProvider>();
}

public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
Expand All @@ -117,3 +117,12 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IRouteableContentTypeProvider, AutorouteContentTypeProvider>();
}
}

[RequireFeatures("OrchardCore.Widgets")]
public sealed class WidgetAutourouteStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IShapeTableProvider, WidgetAutorouteShapeTableProvider>();
}
}

0 comments on commit 8ff5129

Please sign in to comment.