Renames and refactors the MediaUrlGeneratorCollection and ensure that this collection is used wherever IMediaUrlGenerator is needed instead of relying property editors possibly being the implementation.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
@@ -11,17 +9,15 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Gets the url of a media item.
|
||||
/// </summary>
|
||||
public static string GetUrl(this IMedia media, string propertyAlias, ILogger logger, PropertyEditorCollection propertyEditors)
|
||||
public static string GetUrl(this IMedia media, string propertyAlias, MediaUrlGeneratorCollection mediaUrlGenerators)
|
||||
{
|
||||
if (!media.Properties.TryGetValue(propertyAlias, out var property))
|
||||
return string.Empty;
|
||||
|
||||
if (propertyEditors.TryGet(property.PropertyType.PropertyEditorAlias, out var editor)
|
||||
&& editor is IDataEditorWithMediaPath dataEditor)
|
||||
{
|
||||
// TODO: would need to be adjusted to variations, when media become variants
|
||||
var value = property.GetValue();
|
||||
return dataEditor.GetMediaPath(value);
|
||||
// TODO: would need to be adjusted to variations, when media become variants
|
||||
if (mediaUrlGenerators.TryGetMediaPath(property.PropertyType.PropertyEditorAlias, property.GetValue(), out var mediaUrl))
|
||||
{
|
||||
return mediaUrl;
|
||||
}
|
||||
|
||||
// Without knowing what it is, just adding a string here might not be very nice
|
||||
@@ -31,10 +27,10 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Gets the urls of a media item.
|
||||
/// </summary>
|
||||
public static string[] GetUrls(this IMedia media, IContentSection contentSection, ILogger logger, PropertyEditorCollection propertyEditors)
|
||||
public static string[] GetUrls(this IMedia media, IContentSection contentSection, MediaUrlGeneratorCollection mediaUrlGenerators)
|
||||
{
|
||||
return contentSection.ImageAutoFillProperties
|
||||
.Select(field => media.GetUrl(field.Alias, logger, propertyEditors))
|
||||
.Select(field => media.GetUrl(field.Alias, mediaUrlGenerators))
|
||||
.Where(link => string.IsNullOrWhiteSpace(link) == false)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user