From 1885767ef118d17b7d72ec9fcb97b491272b1a3e Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 1 Jul 2019 16:33:09 +1000 Subject: [PATCH] Internalizes the new Anchor logic and removes it from the IContentService interface into extensions. --- .../Services/ContentServiceExtensions.cs | 37 +++++++++++++++++++ src/Umbraco.Core/Services/IContentService.cs | 4 +- .../Services/Implement/ContentService.cs | 34 +---------------- .../src/common/resources/entity.resource.js | 18 --------- src/Umbraco.Web/Editors/EntityController.cs | 20 +--------- 5 files changed, 42 insertions(+), 71 deletions(-) diff --git a/src/Umbraco.Core/Services/ContentServiceExtensions.cs b/src/Umbraco.Core/Services/ContentServiceExtensions.cs index 1175df81dc..dfe02ba690 100644 --- a/src/Umbraco.Core/Services/ContentServiceExtensions.cs +++ b/src/Umbraco.Core/Services/ContentServiceExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; @@ -11,6 +12,42 @@ namespace Umbraco.Core.Services /// public static class ContentServiceExtensions { + #region RTE Anchor values + + private static readonly Regex AnchorRegex = new Regex("", RegexOptions.Compiled); + + internal static IEnumerable GetAnchorValuesFromRTEs(this IContentService contentService, int id, string culture = "*") + { + var result = new List(); + var content = contentService.GetById(id); + + foreach (var contentProperty in content.Properties) + { + if (contentProperty.PropertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.TinyMce)) + { + var value = contentProperty.GetValue(culture)?.ToString(); + if (!string.IsNullOrEmpty(value)) + { + result.AddRange(contentService.GetAnchorValuesFromRTEContent(value)); + } + } + } + return result; + } + + + internal static IEnumerable GetAnchorValuesFromRTEContent(this IContentService contentService, string rteContent) + { + var result = new List(); + var matches = AnchorRegex.Matches(rteContent); + foreach (Match match in matches) + { + result.Add(match.Value.Split('\"')[1]); + } + return result; + } + #endregion + public static IEnumerable GetByIds(this IContentService contentService, IEnumerable ids) { var guids = new List(); diff --git a/src/Umbraco.Core/Services/IContentService.cs b/src/Umbraco.Core/Services/IContentService.cs index a9226fbae2..6f9ca58821 100644 --- a/src/Umbraco.Core/Services/IContentService.cs +++ b/src/Umbraco.Core/Services/IContentService.cs @@ -526,8 +526,6 @@ namespace Umbraco.Core.Services OperationResult Rollback(int id, int versionId, string culture = "*", int userId = Constants.Security.SuperUserId); #endregion - - IEnumerable GetAnchorValuesFromRTEs(int id, string culture = "*"); - IEnumerable GetAnchorValuesFromRTEContent(string rteContent, string culture = "*"); + } } diff --git a/src/Umbraco.Core/Services/Implement/ContentService.cs b/src/Umbraco.Core/Services/Implement/ContentService.cs index 90aaf6fc5d..e49dcf4a12 100644 --- a/src/Umbraco.Core/Services/Implement/ContentService.cs +++ b/src/Umbraco.Core/Services/Implement/ContentService.cs @@ -32,7 +32,7 @@ namespace Umbraco.Core.Services.Implement private IQuery _queryNotTrashed; //TODO: The non-lazy object should be injected private readonly Lazy _propertyValidationService = new Lazy(() => new PropertyValidationService()); - private static readonly Regex AnchorRegex = new Regex("", RegexOptions.Compiled); + #region Constructors @@ -3028,36 +3028,6 @@ namespace Umbraco.Core.Services.Implement #endregion - #region RTE Anchor values - public IEnumerable GetAnchorValuesFromRTEs(int id, string culture = "*") - { - var result = new List(); - var content = GetById(id); - foreach (var contentProperty in content.Properties) - { - if (contentProperty.PropertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.TinyMce)) - { - var value = contentProperty.GetValue(culture)?.ToString(); - if (!string.IsNullOrEmpty(value)) - { - result.AddRange(GetAnchorValuesFromRTEContent(value)); - } - } - } - return result; - } - - - public IEnumerable GetAnchorValuesFromRTEContent(string rteContent, string culture = "*") - { - var result = new List(); - var matches = AnchorRegex.Matches(rteContent); - foreach (Match match in matches) - { - result.Add(match.Value.Split('\"')[1]); - } - return result; - } - #endregion + } } diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js index 95bfd1e49b..eee877a60c 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js @@ -176,24 +176,6 @@ function entityResource($q, $http, umbRequestHelper) { 'Failed to retrieve url and anchors data for id ' + id); }, - - getAnchors: function (rteContent) { - - if (!rteContent || rteContent.length === 0) { - return []; - } - - return umbRequestHelper.resourcePromise( - $http.post( - umbRequestHelper.getApiUrl( - "entityApiBaseUrl", - 'GetAnchors'), - { - rteContent: rteContent - }), - 'Failed to anchors data for rte content ' + rteContent); - }, - /** * @ngdoc method * @name umbraco.resources.entityResource#getByIds diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index 4184182a1d..b0868bd2a6 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -286,30 +286,14 @@ namespace Umbraco.Web.Editors publishedContentExists: i => Umbraco.Content(i) != null); } - - //fixme - culture? [HttpGet] - public UrlAndAnchors GetUrlAndAnchors([FromUri]int id) + public UrlAndAnchors GetUrlAndAnchors([FromUri]int id, [FromUri]string culture = "*") { var url = UmbracoContext.UrlProvider.GetUrl(id); - var anchorValues = Services.ContentService.GetAnchorValuesFromRTEs(id); + var anchorValues = Services.ContentService.GetAnchorValuesFromRTEs(id, culture); return new UrlAndAnchors(url, anchorValues); } - public class AnchorsModel - { - public string RteContent { get; set; } - } - - //fixme - culture? - [HttpGet] - [HttpPost] - public IEnumerable GetAnchors(AnchorsModel model) - { - var anchorValues = Services.ContentService.GetAnchorValuesFromRTEContent(model.RteContent); - return anchorValues; - } - #region GetById