diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/ConvertLocalLinks.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/ConvertLocalLinks.cs index 1f822236f80e..cf7c2015a4c0 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/ConvertLocalLinks.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/ConvertLocalLinks.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using NPoco; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Models; @@ -23,7 +22,6 @@ public class ConvertLocalLinks : MigrationBase private readonly ILanguageService _languageService; private readonly IJsonSerializer _jsonSerializer; private readonly LocalLinkProcessor _convertLocalLinkProcessor; - private readonly IOptions _options; public ConvertLocalLinks( IMigrationContext context, @@ -33,8 +31,7 @@ public ConvertLocalLinks( IDataTypeService dataTypeService, ILanguageService languageService, IJsonSerializer jsonSerializer, - LocalLinkProcessor convertLocalLinkProcessor, - IOptions options) + LocalLinkProcessor convertLocalLinkProcessor) : base(context) { _umbracoContextFactory = umbracoContextFactory; @@ -44,12 +41,10 @@ public ConvertLocalLinks( _languageService = languageService; _jsonSerializer = jsonSerializer; _convertLocalLinkProcessor = convertLocalLinkProcessor; - _options = options; } protected override void Migrate() { - _convertLocalLinkProcessor.Initialize(_options.Value.Processors); IEnumerable propertyEditorAliases = _convertLocalLinkProcessor.GetSupportedPropertyEditorAliases(); using UmbracoContextReference umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext(); diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/LocalLinks/ConvertLocalLinkComposer.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/LocalLinks/ConvertLocalLinkComposer.cs index 49e81efc7d14..6663a7434cfc 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/LocalLinks/ConvertLocalLinkComposer.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/LocalLinks/ConvertLocalLinkComposer.cs @@ -3,6 +3,7 @@ using Umbraco.Cms.Core; using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.Models.Blocks; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Templates; using Umbraco.Extensions; @@ -17,8 +18,8 @@ public void Compose(IUmbracoBuilder builder) builder.Services.AddUnique(provider => new LocalLinkProcessor( provider.GetRequiredService(), - provider.GetRequiredService(), - provider.GetRequiredService>())); + provider.GetRequiredService(), + provider.GetRequiredService>>())); builder.Services.AddUnique(provider => new LocalLinkBlocksProcessor(provider.GetRequiredService())); builder.Services.AddUnique(provider => new LocalLinkRteProcessor(provider.GetRequiredService())); builder.Services.ConfigureOptions(); @@ -47,8 +48,13 @@ public void Configure(ConvertLocalLinkOptions options) _linkLinkRteProcessor.ProcessRichText)); options.Processors.Add(new ProcessorInformation( - typeof(RichTextEditorValue), - [Constants.PropertyEditors.Aliases.BlockList, Constants.PropertyEditors.Aliases.BlockGrid], + typeof(BlockListValue), + [Constants.PropertyEditors.Aliases.BlockList], + _localLinkBlocksProcessor.ProcessBlocks)); + + options.Processors.Add(new ProcessorInformation( + typeof(BlockGridValue), + [Constants.PropertyEditors.Aliases.BlockGrid], _localLinkBlocksProcessor.ProcessBlocks)); } } diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/LocalLinks/ConvertLocalLinkOptions.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/LocalLinks/ConvertLocalLinkOptions.cs index 4868f544c9a1..7d2f502dae3d 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/LocalLinks/ConvertLocalLinkOptions.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/LocalLinks/ConvertLocalLinkOptions.cs @@ -3,17 +3,17 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_15_0_0.LocalLinks; [Obsolete("Will be removed in V18")] public class ConvertLocalLinkOptions { - public List Processors { get; } = new(); + public List Processors { get; } = []; } [Obsolete("Will be removed in V18")] public class ProcessorInformation { - public Type PropertyEditorValueType { get; init; } + public Type PropertyEditorValueType { get; } - public IEnumerable PropertyEditorAliases { get; init; } + public IEnumerable PropertyEditorAliases { get; } - public Func Process { get; init; } + public Func Process { get; } public ProcessorInformation(Type propertyEditorValueType, IEnumerable propertyEditorAliases, Func process) { diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/LocalLinks/LocalLinkProcessor.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/LocalLinks/LocalLinkProcessor.cs index 1e199062b545..a56e88c4166c 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/LocalLinks/LocalLinkProcessor.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/LocalLinks/LocalLinkProcessor.cs @@ -10,24 +10,24 @@ public class LocalLinkProcessor { private readonly HtmlLocalLinkParser _localLinkParser; private readonly IIdKeyMap _idKeyMap; - private List _processors; + private readonly Lazy> _lazyOptions; public LocalLinkProcessor( HtmlLocalLinkParser localLinkParser, IIdKeyMap idKeyMap, - IOptions options) + Lazy> lazyOptions) { _localLinkParser = localLinkParser; _idKeyMap = idKeyMap; - _processors = options.Value.Processors; + _lazyOptions = lazyOptions; } public IEnumerable GetSupportedPropertyEditorAliases() => - _processors.SelectMany(p => p.PropertyEditorAliases); + _lazyOptions.Value.Value.Processors.SelectMany(p => p.PropertyEditorAliases); public bool ProcessToEditorValue(object? editorValue) { - ProcessorInformation? processor = _processors.FirstOrDefault(p => p.PropertyEditorValueType == editorValue?.GetType()); + ProcessorInformation? processor = _lazyOptions.Value.Value.Processors.FirstOrDefault(p => p.PropertyEditorValueType == editorValue?.GetType()); return processor is not null && processor.Process.Invoke(editorValue); } @@ -35,7 +35,7 @@ public bool ProcessToEditorValue(object? editorValue) public string ProcessStringValue(string input) { // find all legacy tags - IEnumerable tags = _localLinkParser.FindLegacyLocalLinkIds(input); + var tags = _localLinkParser.FindLegacyLocalLinkIds(input).ToList(); foreach (HtmlLocalLinkParser.LocalLinkTag tag in tags) {