From 117b298d0bfcf1dd5faad7352027fe904edbdb30 Mon Sep 17 00:00:00 2001 From: Mikhail Lipin Date: Thu, 2 May 2024 21:29:58 +0300 Subject: [PATCH] Issue-15713: Fix creating Culture and LocalizationSet for contents created via Graph API. (#15714) --- .../Handlers/LocalizationPartHandler.cs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/LocalizationPartHandler.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/LocalizationPartHandler.cs index 8525814fb08..3179c8b6014 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/LocalizationPartHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/LocalizationPartHandler.cs @@ -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 { 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(p => + p.LocalizationSet = _idGenerator.GenerateUniqueId() + ); + } + + if (string.IsNullOrEmpty(part.Culture)) + { + await context.ContentItem.AlterAsync(async p => + p.Culture = await _localizationService.GetDefaultCultureAsync() + ); + } + } + public override Task GetContentItemAspectAsync(ContentItemAspectContext context, LocalizationPart part) { return context.ForAsync(cultureAspect =>