From a491b55dbdd001f1e36e1c1a4c3021288d081d86 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Tue, 23 Apr 2024 08:55:35 +0300 Subject: [PATCH 1/7] Avoid cloning the AutoPart pattern in the localized content --- .../DefaultContentLocalizationManager.cs | 7 +++++++ .../OrchardCore.ContentLocalization.csproj | 1 + 2 files changed, 8 insertions(+) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/DefaultContentLocalizationManager.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/DefaultContentLocalizationManager.cs index 85c24505a43..a2e4abea9e0 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/DefaultContentLocalizationManager.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/DefaultContentLocalizationManager.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Localization; using Microsoft.Extensions.Logging; +using OrchardCore.Autoroute.Models; using OrchardCore.ContentLocalization.Handlers; using OrchardCore.ContentLocalization.Models; using OrchardCore.ContentLocalization.Records; @@ -102,6 +103,12 @@ public async Task LocalizeAsync(ContentItem content, string targetC clonedPart.LocalizationSet = localizationPart.LocalizationSet; clonedPart.Apply(); + // Clearing the autopart path to regenerate the permalink automatically + if (cloned.Has()) + { + cloned.Content.AutoroutePart.Path = null; + } + var context = new LocalizationContentContext(cloned, content, localizationPart.LocalizationSet, targetCulture); await Handlers.InvokeAsync((handler, context) => handler.LocalizingAsync(context), context, _logger); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/OrchardCore.ContentLocalization.csproj b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/OrchardCore.ContentLocalization.csproj index 4279273e575..65a42de669f 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/OrchardCore.ContentLocalization.csproj +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/OrchardCore.ContentLocalization.csproj @@ -17,6 +17,7 @@ + From 4e8b6cbdee4940df9008b482f2f31552698af1dc Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Thu, 2 May 2024 01:04:27 +0300 Subject: [PATCH 2/7] Address feedback --- .../DefaultContentLocalizationManager.cs | 7 -- .../AutoPartContentLocalizationHandler.cs | 21 ++++ .../Startup.cs | 113 ++++++++++-------- 3 files changed, 82 insertions(+), 59 deletions(-) create mode 100644 src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/DefaultContentLocalizationManager.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/DefaultContentLocalizationManager.cs index a2e4abea9e0..85c24505a43 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/DefaultContentLocalizationManager.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/DefaultContentLocalizationManager.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Localization; using Microsoft.Extensions.Logging; -using OrchardCore.Autoroute.Models; using OrchardCore.ContentLocalization.Handlers; using OrchardCore.ContentLocalization.Models; using OrchardCore.ContentLocalization.Records; @@ -103,12 +102,6 @@ public async Task LocalizeAsync(ContentItem content, string targetC clonedPart.LocalizationSet = localizationPart.LocalizationSet; clonedPart.Apply(); - // Clearing the autopart path to regenerate the permalink automatically - if (cloned.Has()) - { - cloned.Content.AutoroutePart.Path = null; - } - var context = new LocalizationContentContext(cloned, content, localizationPart.LocalizationSet, targetCulture); await Handlers.InvokeAsync((handler, context) => handler.LocalizingAsync(context), context, _logger); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs new file mode 100644 index 00000000000..46063faa512 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs @@ -0,0 +1,21 @@ +using System.Threading.Tasks; +using OrchardCore.Autoroute.Models; +using OrchardCore.ContentManagement; + +namespace OrchardCore.ContentLocalization.Handlers; + +public class AutoPartContentLocalizationHandler : IContentLocalizationHandler +{ + public Task LocalizedAsync(LocalizationContentContext context) => Task.CompletedTask; + + public Task LocalizingAsync(LocalizationContentContext context) + { + if (context.ContentItem.Has()) + { + // Clearing the autopart path to regenerate the permalink automatically + context.ContentItem.Content.AutoroutePart.Path = null; + } + + return Task.CompletedTask; + } +} diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs index 337ca81f121..3269562e2bd 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using OrchardCore.Admin.Models; using OrchardCore.ContentLocalization.Drivers; +using OrchardCore.ContentLocalization.Handlers; using OrchardCore.ContentLocalization.Indexing; using OrchardCore.ContentLocalization.Liquid; using OrchardCore.ContentLocalization.Security; @@ -26,71 +27,79 @@ using OrchardCore.Settings; using OrchardCore.Sitemaps.Builders; -namespace OrchardCore.ContentLocalization +namespace OrchardCore.ContentLocalization; + +public class Startup : StartupBase { - public class Startup : StartupBase + public override void ConfigureServices(IServiceCollection services) { - public override void ConfigureServices(IServiceCollection services) + services.Configure(o => { - services.Configure(o => - { - o.MemberAccessStrategy.Register(); - o.MemberAccessStrategy.Register(); - }) - .AddLiquidFilter("localization_set"); + o.MemberAccessStrategy.Register(); + o.MemberAccessStrategy.Register(); + }) + .AddLiquidFilter("localization_set"); - services.AddScoped(); - services.AddSingleton(); - services.AddContentLocalization(); + services.AddScoped(); + services.AddSingleton(); + services.AddContentLocalization(); - services.AddScoped(); - services.AddScoped(); + services.AddScoped(); + services.AddScoped(); - services.AddScoped(); - services.AddTransient(); - services.AddScoped, LocalizationContentsAdminListDisplayDriver>(); - } + services.AddScoped(); + services.AddTransient(); + services.AddScoped, LocalizationContentsAdminListDisplayDriver>(); } +} - [Feature("OrchardCore.ContentLocalization.ContentCulturePicker")] - public class ContentPickerStartup : StartupBase +[Feature("OrchardCore.ContentLocalization.ContentCulturePicker")] +public class ContentPickerStartup : StartupBase +{ + private readonly IShellConfiguration _shellConfiguration; + public ContentPickerStartup(IShellConfiguration shellConfiguration) { - private readonly IShellConfiguration _shellConfiguration; - public ContentPickerStartup(IShellConfiguration shellConfiguration) - { - _shellConfiguration = shellConfiguration; - } + _shellConfiguration = shellConfiguration; + } - public override void ConfigureServices(IServiceCollection services) - { - services.AddScoped, ContentCulturePickerNavbarDisplayDriver>(); - services.AddLiquidFilter("switch_culture_url"); - services.AddScoped(); - services.AddScoped(); - services.AddScoped, ContentCulturePickerSettingsDriver>(); - services.AddScoped, ContentRequestCultureProviderSettingsDriver>(); - services.Configure(options => options.AddInitialRequestCultureProvider(new ContentRequestCultureProvider())); - services.Configure(_shellConfiguration.GetSection("OrchardCore_ContentLocalization_CulturePickerOptions")); - } + public override void ConfigureServices(IServiceCollection services) + { + services.AddScoped, ContentCulturePickerNavbarDisplayDriver>(); + services.AddLiquidFilter("switch_culture_url"); + services.AddScoped(); + services.AddScoped(); + services.AddScoped, ContentCulturePickerSettingsDriver>(); + services.AddScoped, ContentRequestCultureProviderSettingsDriver>(); + services.Configure(options => options.AddInitialRequestCultureProvider(new ContentRequestCultureProvider())); + services.Configure(_shellConfiguration.GetSection("OrchardCore_ContentLocalization_CulturePickerOptions")); + } - public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) - { - routes.MapAreaControllerRoute( - name: "RedirectToLocalizedContent", - areaName: "OrchardCore.ContentLocalization", - pattern: "RedirectToLocalizedContent", - defaults: new { controller = "ContentCulturePicker", action = "RedirectToLocalizedContent" } - ); - } + public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) + { + routes.MapAreaControllerRoute( + name: "RedirectToLocalizedContent", + areaName: "OrchardCore.ContentLocalization", + pattern: "RedirectToLocalizedContent", + defaults: new { controller = "ContentCulturePicker", action = "RedirectToLocalizedContent" } + ); } +} - [Feature("OrchardCore.ContentLocalization.Sitemaps")] - public class SitemapsStartup : StartupBase +[Feature("OrchardCore.ContentLocalization.Sitemaps")] +public class SitemapsStartup : StartupBase +{ + public override void ConfigureServices(IServiceCollection services) { - public override void ConfigureServices(IServiceCollection services) - { - services.AddScoped(); - services.Replace(ServiceDescriptor.Scoped()); - } + services.AddScoped(); + services.Replace(ServiceDescriptor.Scoped()); + } +} + +[Feature("OrchardCore.Autoroute")] +public class AutoPartStartup : StartupBase +{ + public override void ConfigureServices(IServiceCollection services) + { + services.AddScoped(); } } From 69793d27c5c39738162800b40d49aa7fecb7cdb5 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Thu, 2 May 2024 19:38:33 +0300 Subject: [PATCH 3/7] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zoltán Lehóczky --- .../Handlers/AutoPartContentLocalizationHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs index 46063faa512..1b16c4dda5a 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs @@ -4,7 +4,7 @@ namespace OrchardCore.ContentLocalization.Handlers; -public class AutoPartContentLocalizationHandler : IContentLocalizationHandler +public class AutoroutePartContentLocalizationHandler : IContentLocalizationHandler { public Task LocalizedAsync(LocalizationContentContext context) => Task.CompletedTask; @@ -12,7 +12,7 @@ public Task LocalizingAsync(LocalizationContentContext context) { if (context.ContentItem.Has()) { - // Clearing the autopart path to regenerate the permalink automatically + // Clearing the AutoroutePart path to regenerate the permalink automatically. context.ContentItem.Content.AutoroutePart.Path = null; } From 2f6f73b8bb672833cd4e134e8a7694d37493349c Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Thu, 2 May 2024 19:43:49 +0300 Subject: [PATCH 4/7] Move AutorouteContentLocalizationHandler to Autoroute module --- .../Handlers/AutorouteContentLocalizationHandler.cs} | 2 +- .../OrchardCore.Autoroute/Startup.cs | 10 ++++++++++ .../OrchardCore.ContentLocalization.csproj | 1 - .../OrchardCore.ContentLocalization/Startup.cs | 10 ---------- 4 files changed, 11 insertions(+), 12 deletions(-) rename src/OrchardCore.Modules/{OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs => OrchardCore.Autoroute/Handlers/AutorouteContentLocalizationHandler.cs} (87%) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutorouteContentLocalizationHandler.cs similarity index 87% rename from src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs rename to src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutorouteContentLocalizationHandler.cs index 1b16c4dda5a..9396bba94d1 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutorouteContentLocalizationHandler.cs @@ -4,7 +4,7 @@ namespace OrchardCore.ContentLocalization.Handlers; -public class AutoroutePartContentLocalizationHandler : IContentLocalizationHandler +public class AutorouteContentLocalizationHandler : IContentLocalizationHandler { public Task LocalizedAsync(LocalizationContentContext context) => Task.CompletedTask; diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Startup.cs index 13573cc11ef..6e996c25070 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Startup.cs @@ -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; @@ -113,4 +114,13 @@ public override void ConfigureServices(IServiceCollection services) services.AddScoped(); } } + + [RequireFeatures("OrchardCore.Autoroute")] + public class AutoPartStartup : StartupBase + { + public override void ConfigureServices(IServiceCollection services) + { + services.AddScoped(); + } + } } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/OrchardCore.ContentLocalization.csproj b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/OrchardCore.ContentLocalization.csproj index 65a42de669f..4279273e575 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/OrchardCore.ContentLocalization.csproj +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/OrchardCore.ContentLocalization.csproj @@ -17,7 +17,6 @@ - diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs index 3269562e2bd..fdd7e8f6c5a 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs @@ -8,7 +8,6 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using OrchardCore.Admin.Models; using OrchardCore.ContentLocalization.Drivers; -using OrchardCore.ContentLocalization.Handlers; using OrchardCore.ContentLocalization.Indexing; using OrchardCore.ContentLocalization.Liquid; using OrchardCore.ContentLocalization.Security; @@ -94,12 +93,3 @@ public override void ConfigureServices(IServiceCollection services) services.Replace(ServiceDescriptor.Scoped()); } } - -[Feature("OrchardCore.Autoroute")] -public class AutoPartStartup : StartupBase -{ - public override void ConfigureServices(IServiceCollection services) - { - services.AddScoped(); - } -} From 11280d1cf11e6361a9f87b6f0b27c4aa204659a8 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Thu, 2 May 2024 20:41:54 +0300 Subject: [PATCH 5/7] Address feedback --- .../Handlers/AutorouteContentLocalizationHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutorouteContentLocalizationHandler.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutorouteContentLocalizationHandler.cs index 9396bba94d1..d6bf5873572 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutorouteContentLocalizationHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutorouteContentLocalizationHandler.cs @@ -13,7 +13,7 @@ public Task LocalizingAsync(LocalizationContentContext context) if (context.ContentItem.Has()) { // Clearing the AutoroutePart path to regenerate the permalink automatically. - context.ContentItem.Content.AutoroutePart.Path = null; + context.ContentItem.Alter(p => p.Path = null); } return Task.CompletedTask; From bd997d05b425cb3ffe861a1791e45557519dc0aa Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Mon, 17 Jun 2024 08:59:52 +0300 Subject: [PATCH 6/7] Fix the build --- .../OrchardCore.ContentLocalization/Startup.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs index 70d08cb3a54..4fc57bd4112 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs @@ -39,16 +39,17 @@ public override void ConfigureServices(IServiceCollection services) }) .AddLiquidFilter("localization_set"); - services.AddScoped(); - services.AddSingleton(); - services.AddContentLocalization(); + services.AddScoped(); + services.AddSingleton(); + services.AddContentLocalization(); - services.AddScoped(); - services.AddScoped(); + services.AddScoped(); + services.AddScoped(); - services.AddScoped(); - services.AddTransient(); - services.AddScoped, LocalizationContentsAdminListDisplayDriver>(); + services.AddScoped(); + services.AddTransient(); + services.AddScoped, LocalizationContentsAdminListDisplayDriver>(); + }); } } From 62466349e3bf97b9ec1ebcaec3755e147e34bdcb Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Mon, 17 Jun 2024 09:49:47 +0300 Subject: [PATCH 7/7] Don't use Alert() --- .../AutorouteContentLocalizationHandler.cs | 2 +- .../Startup.cs | 25 ++++++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutorouteContentLocalizationHandler.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutorouteContentLocalizationHandler.cs index d6bf5873572..9396bba94d1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutorouteContentLocalizationHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutorouteContentLocalizationHandler.cs @@ -13,7 +13,7 @@ public Task LocalizingAsync(LocalizationContentContext context) if (context.ContentItem.Has()) { // Clearing the AutoroutePart path to regenerate the permalink automatically. - context.ContentItem.Alter(p => p.Path = null); + context.ContentItem.Content.AutoroutePart.Path = null; } return Task.CompletedTask; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs index 4fc57bd4112..f5f29aa1a9d 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs @@ -33,23 +33,20 @@ public override void ConfigureServices(IServiceCollection services) { services.Configure(o => { - services.Configure(o => - { - o.MemberAccessStrategy.Register(); - }) - .AddLiquidFilter("localization_set"); + o.MemberAccessStrategy.Register(); + }) + .AddLiquidFilter("localization_set"); - services.AddScoped(); - services.AddSingleton(); - services.AddContentLocalization(); + services.AddScoped(); + services.AddSingleton(); + services.AddContentLocalization(); - services.AddScoped(); - services.AddScoped(); + services.AddScoped(); + services.AddScoped(); - services.AddScoped(); - services.AddTransient(); - services.AddScoped, LocalizationContentsAdminListDisplayDriver>(); - }); + services.AddScoped(); + services.AddTransient(); + services.AddScoped, LocalizationContentsAdminListDisplayDriver>(); } }