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 all 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 @@ -133,4 +134,13 @@ public override void ConfigureServices(IServiceCollection services)
{
services.AddShapeTableProvider<WidgetAutorouteShapeTableProvider>();
}

[RequireFeatures("OrchardCore.Autoroute")]
public class AutoPartStartup : 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.AddScoped<IDisplayDriver<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