Skip to content

Commit

Permalink
Avoid cloning the AutoroutePart pattern in the localized content (#15810
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hishamco authored Jan 26, 2025
1 parent 13cda4d commit bee9b18
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Threading.Tasks;
using OrchardCore.Autoroute.Models;
using OrchardCore.ContentManagement;

namespace OrchardCore.ContentLocalization.Handlers;

internal sealed class AutorouteContentLocalizationHandler : IContentLocalizationHandler
{
public Task LocalizedAsync(LocalizationContentContext context) => Task.CompletedTask;

public Task LocalizingAsync(LocalizationContentContext context)
{
if (context.ContentItem.Has<AutoroutePart>())
{
// Clearing the AutoroutePart path to regenerate the permalink automatically.
context.ContentItem.Alter<AutoroutePart>(p => p.Path = null);
}

return Task.CompletedTask;
}
}
10 changes: 10 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Autoroute/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using OrchardCore.Autoroute.Settings;
using OrchardCore.Autoroute.Sitemaps;
using OrchardCore.Autoroute.ViewModels;
using OrchardCore.ContentLocalization.Handlers;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.GraphQL.Options;
Expand Down Expand Up @@ -133,3 +134,12 @@ public override void ConfigureServices(IServiceCollection services)
services.AddShapeTableProvider<WidgetAutorouteShapeTableProvider>();
}
}

[RequireFeatures("OrchardCore.ContentLocalization")]
public class ContentLocalizationStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IContentLocalizationHandler, AutorouteContentLocalizationHandler>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public override void ConfigureServices(IServiceCollection services)
public sealed class ContentPickerStartup : StartupBase
{
private readonly IShellConfiguration _shellConfiguration;

public ContentPickerStartup(IShellConfiguration shellConfiguration)
{
_shellConfiguration = shellConfiguration;
Expand All @@ -61,10 +62,12 @@ public override void ConfigureServices(IServiceCollection services)
{
services.AddDisplayDriver<Navbar, ContentCulturePickerNavbarDisplayDriver>();
services.AddLiquidFilter<SwitchCultureUrlFilter>("switch_culture_url");

services.AddNavigationProvider<AdminMenu>();
services.AddScoped<IContentCulturePickerService, ContentCulturePickerService>();
services.AddSiteDisplayDriver<ContentCulturePickerSettingsDriver>();
services.AddSiteDisplayDriver<ContentRequestCultureProviderSettingsDriver>();

services.Configure<RequestLocalizationOptions>(options => options.AddInitialRequestCultureProvider(new ContentRequestCultureProvider()));
services.Configure<CulturePickerOptions>(_shellConfiguration.GetSection("OrchardCore_ContentLocalization_CulturePickerOptions"));
}
Expand Down

0 comments on commit bee9b18

Please sign in to comment.