Internalizes the new Anchor logic and removes it from the IContentService interface into extensions.

This commit is contained in:
Shannon
2019-07-01 16:33:09 +10:00
parent 80e6880bb7
commit 1885767ef1
5 changed files with 42 additions and 71 deletions

View File

@@ -32,7 +32,7 @@ namespace Umbraco.Core.Services.Implement
private IQuery<IContent> _queryNotTrashed;
//TODO: The non-lazy object should be injected
private readonly Lazy<PropertyValidationService> _propertyValidationService = new Lazy<PropertyValidationService>(() => new PropertyValidationService());
private static readonly Regex AnchorRegex = new Regex("<a id=\"(.*?)\">", RegexOptions.Compiled);
#region Constructors
@@ -3028,36 +3028,6 @@ namespace Umbraco.Core.Services.Implement
#endregion
#region RTE Anchor values
public IEnumerable<string> GetAnchorValuesFromRTEs(int id, string culture = "*")
{
var result = new List<string>();
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<string> GetAnchorValuesFromRTEContent(string rteContent, string culture = "*")
{
var result = new List<string>();
var matches = AnchorRegex.Matches(rteContent);
foreach (Match match in matches)
{
result.Add(match.Value.Split('\"')[1]);
}
return result;
}
#endregion
}
}