From 1ba834a9ca4a44a38d24843c72f8d87f481f6f34 Mon Sep 17 00:00:00 2001 From: Marco Teodoro Date: Fri, 16 Jun 2023 13:40:19 +0100 Subject: [PATCH] fix: #12253 Anchor picker does not appear (#13492) * fix: #12253 Anchor picker does not appear * Update ContentServiceExtensions.cs fix: #12253 #13492 ; implement PR suggestions, test the new changes to confirm that they fix the issue with the anchorlink implementation on RTE from blocklist, blockgrid and normal RTE properties Co-Authored-By: Laura Neto <12862535+lauraneto@users.noreply.github.com> * Removed unnecessary using and code * Small adjustments --------- Co-authored-by: Laura Neto <12862535+lauraneto@users.noreply.github.com> --- .../Services/ContentServiceExtensions.cs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Core/Services/ContentServiceExtensions.cs b/src/Umbraco.Core/Services/ContentServiceExtensions.cs index b042612b1a..aaba622412 100644 --- a/src/Umbraco.Core/Services/ContentServiceExtensions.cs +++ b/src/Umbraco.Core/Services/ContentServiceExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Umbraco. +// Copyright (c) Umbraco. // See LICENSE for more details. using System.Text.RegularExpressions; @@ -16,7 +16,8 @@ public static class ContentServiceExtensions { #region RTE Anchor values - private static readonly Regex AnchorRegex = new("", RegexOptions.Compiled); + private static readonly Regex AnchorRegex = new(@"", RegexOptions.Compiled); + private static readonly string[] _propertyTypesWithRte = new[] { Constants.PropertyEditors.Aliases.TinyMce, Constants.PropertyEditors.Aliases.BlockList, Constants.PropertyEditors.Aliases.BlockGrid }; public static IEnumerable? GetByIds(this IContentService contentService, IEnumerable ids) { @@ -67,21 +68,22 @@ public static class ContentServiceExtensions public static IEnumerable GetAnchorValuesFromRTEs(this IContentService contentService, int id, string? culture = "*") { var result = new List(); + + culture = culture is not "*" ? culture : null; + IContent? content = contentService.GetById(id); - if (content is not null) + if (content is null) { - foreach (IProperty contentProperty in content.Properties) + return result; + } + + foreach (IProperty contentProperty in content.Properties.Where(s => _propertyTypesWithRte.Contains(s.PropertyType.PropertyEditorAlias))) + { + var value = contentProperty.GetValue(culture)?.ToString(); + if (!string.IsNullOrEmpty(value)) { - if (contentProperty.PropertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases - .TinyMce)) - { - var value = contentProperty.GetValue(culture)?.ToString(); - if (!string.IsNullOrEmpty(value)) - { - result.AddRange(contentService.GetAnchorValuesFromRTEContent(value)); - } - } + result.AddRange(contentService.GetAnchorValuesFromRTEContent(value)); } } @@ -96,7 +98,7 @@ public static class ContentServiceExtensions MatchCollection matches = AnchorRegex.Matches(rteContent); foreach (Match match in matches) { - result.Add(match.Value.Split(Constants.CharArrays.DoubleQuote)[1]); + result.Add(match.Groups[1].Value); } return result;