Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid cloning the AutoroutePart pattern in the localized content #15810

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Piedone marked this conversation as resolved.
Show resolved Hide resolved
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;

public class AutoPartContentLocalizationHandler : IContentLocalizationHandler
hishamco marked this conversation as resolved.
Show resolved Hide resolved
{
public Task LocalizedAsync(LocalizationContentContext context) => Task.CompletedTask;

public Task LocalizingAsync(LocalizationContentContext context)
{
if (context.ContentItem.Has<AutoroutePart>())
{
// Clearing the autopart path to regenerate the permalink automatically
hishamco marked this conversation as resolved.
Show resolved Hide resolved
context.ContentItem.Content.AutoroutePart.Path = null;
}

return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<ItemGroup>
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Admin.Abstractions\OrchardCore.Admin.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Apis.GraphQL.Abstractions\OrchardCore.Apis.GraphQL.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Autoroute.Core\OrchardCore.Autoroute.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ContentLocalization.Abstractions\OrchardCore.ContentLocalization.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ContentManagement.Abstractions\OrchardCore.ContentManagement.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ContentManagement.GraphQL\OrchardCore.ContentManagement.GraphQL.csproj" />
Expand Down
113 changes: 61 additions & 52 deletions src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<TemplateOptions>(o =>
{
services.Configure<TemplateOptions>(o =>
{
o.MemberAccessStrategy.Register<LocalizationPartViewModel>();
o.MemberAccessStrategy.Register<CultureInfo>();
})
.AddLiquidFilter<ContentLocalizationFilter>("localization_set");
o.MemberAccessStrategy.Register<LocalizationPartViewModel>();
o.MemberAccessStrategy.Register<CultureInfo>();
})
.AddLiquidFilter<ContentLocalizationFilter>("localization_set");

services.AddScoped<IContentPartIndexHandler, LocalizationPartIndexHandler>();
services.AddSingleton<ILocalizationEntries, LocalizationEntries>();
services.AddContentLocalization();
services.AddScoped<IContentPartIndexHandler, LocalizationPartIndexHandler>();
services.AddSingleton<ILocalizationEntries, LocalizationEntries>();
services.AddContentLocalization();

services.AddScoped<IPermissionProvider, Permissions>();
services.AddScoped<IAuthorizationHandler, LocalizeContentAuthorizationHandler>();
services.AddScoped<IPermissionProvider, Permissions>();
services.AddScoped<IAuthorizationHandler, LocalizeContentAuthorizationHandler>();

services.AddScoped<IContentsAdminListFilter, LocalizationPartContentsAdminListFilter>();
services.AddTransient<IContentsAdminListFilterProvider, LocalizationPartContentsAdminListFilterProvider>();
services.AddScoped<IDisplayDriver<ContentOptionsViewModel>, LocalizationContentsAdminListDisplayDriver>();
}
services.AddScoped<IContentsAdminListFilter, LocalizationPartContentsAdminListFilter>();
services.AddTransient<IContentsAdminListFilterProvider, LocalizationPartContentsAdminListFilterProvider>();
services.AddScoped<IDisplayDriver<ContentOptionsViewModel>, 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<IDisplayDriver<Navbar>, ContentCulturePickerNavbarDisplayDriver>();
services.AddLiquidFilter<SwitchCultureUrlFilter>("switch_culture_url");
services.AddScoped<INavigationProvider, AdminMenu>();
services.AddScoped<IContentCulturePickerService, ContentCulturePickerService>();
services.AddScoped<IDisplayDriver<ISite>, ContentCulturePickerSettingsDriver>();
services.AddScoped<IDisplayDriver<ISite>, ContentRequestCultureProviderSettingsDriver>();
services.Configure<RequestLocalizationOptions>(options => options.AddInitialRequestCultureProvider(new ContentRequestCultureProvider()));
services.Configure<CulturePickerOptions>(_shellConfiguration.GetSection("OrchardCore_ContentLocalization_CulturePickerOptions"));
}
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IDisplayDriver<Navbar>, ContentCulturePickerNavbarDisplayDriver>();
services.AddLiquidFilter<SwitchCultureUrlFilter>("switch_culture_url");
services.AddScoped<INavigationProvider, AdminMenu>();
services.AddScoped<IContentCulturePickerService, ContentCulturePickerService>();
services.AddScoped<IDisplayDriver<ISite>, ContentCulturePickerSettingsDriver>();
services.AddScoped<IDisplayDriver<ISite>, ContentRequestCultureProviderSettingsDriver>();
services.Configure<RequestLocalizationOptions>(options => options.AddInitialRequestCultureProvider(new ContentRequestCultureProvider()));
services.Configure<CulturePickerOptions>(_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<ISitemapContentItemExtendedMetadataProvider, SitemapUrlHrefLangExtendedMetadataProvider>();
services.Replace(ServiceDescriptor.Scoped<IContentItemsQueryProvider, LocalizedContentItemsQueryProvider>());
}
services.AddScoped<ISitemapContentItemExtendedMetadataProvider, SitemapUrlHrefLangExtendedMetadataProvider>();
services.Replace(ServiceDescriptor.Scoped<IContentItemsQueryProvider, LocalizedContentItemsQueryProvider>());
}
}

[Feature("OrchardCore.Autoroute")]
public class AutoPartStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IContentLocalizationHandler, AutoPartContentLocalizationHandler>();
}
}
Loading