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 8 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't fix the issue:

2024-05-02_20h06_41.mp4

Copy link
Member Author

@hishamco hishamco May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try it without your last suggestion - Using Alter - I'm 100% percentage sure it was working as expected

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird I don't know why the

context.ContentItem.Alter<AutoroutePart>(p => p.Path = null);

doesn't work as expected here?!! Do you have any idea or shall I revert the last change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good, but please make it work in a statically typed way. We don't need dynamic for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, sorry, I'd also need to get into debugging this to figure it out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to revise this, using CloningAsync() might resolve the issue but not make sense while LocalizingAsync() should be the suited event for that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if that is the case, then call _session.SaveAsync() after calling LocalizingAsync. But honestly, this sounds like a bad idea to me. IContentHandler should be the right event to hook into at that point. LocalizingAsync should not be used to alter the content item.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocalizingAsync should not be used to alter the content item.

For that I alert the autoroute path without using Alter() just to solve the above issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a test case for the Alter method to make sure STJ isn't causing a problem? Alter should work.

Copy link
Member Author

@hishamco hishamco May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is #15714 a recent PR that I merged, the Alter was working fine

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 AutorouteContentLocalizationHandler : IContentLocalizationHandler
Piedone 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 AutoroutePart path to regenerate the permalink automatically.
context.ContentItem.Content.AutoroutePart.Path = null;
Piedone marked this conversation as resolved.
Show resolved Hide resolved
}

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 @@ -113,4 +114,13 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IRouteableContentTypeProvider, AutorouteContentTypeProvider>();
}
}

[RequireFeatures("OrchardCore.Autoroute")]
public class AutoPartStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IContentLocalizationHandler, AutorouteContentLocalizationHandler>();
}
}
}
103 changes: 51 additions & 52 deletions src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,71 +26,70 @@
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>());
}
}