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

Fix creating Culture and LocalizationSet #15714

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,44 @@
using OrchardCore.ContentLocalization.Services;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Handlers;
using OrchardCore.Entities;
using OrchardCore.Localization;

namespace OrchardCore.ContentLocalization.Handlers
{
public class LocalizationPartHandler : ContentPartHandler<LocalizationPart>
{
private readonly ILocalizationEntries _entries;
private readonly IIdGenerator _idGenerator;
private readonly ILocalizationService _localizationService;

public LocalizationPartHandler(ILocalizationEntries entries)
public LocalizationPartHandler(
ILocalizationEntries entries,
IIdGenerator idGenerator,
ILocalizationService localizationService)
{
_entries = entries;
_idGenerator = idGenerator;
_localizationService = localizationService;
}

public override async Task CreatingAsync(CreateContentContext context, LocalizationPart part)
{
if (string.IsNullOrEmpty(part.LocalizationSet))
{
context.ContentItem.Alter<LocalizationPart>(p =>
p.LocalizationSet = _idGenerator.GenerateUniqueId()
);
}

if (string.IsNullOrEmpty(part.Culture))
{
await context.ContentItem.AlterAsync<LocalizationPart>(async p =>
p.Culture = await _localizationService.GetDefaultCultureAsync()
);
}
}

public override Task GetContentItemAspectAsync(ContentItemAspectContext context, LocalizationPart part)
{
return context.ForAsync<CultureAspect>(cultureAspect =>
Expand Down