Removes the need for another .Current and a lookup, simplifies the whole GetUrl for media

This commit is contained in:
Shannon
2019-02-07 12:02:47 +11:00
parent 562855a687
commit 9df0f384af

View File

@@ -16,21 +16,17 @@ namespace Umbraco.Core.Models
/// </summary>
public static string GetUrl(this IMedia media, string propertyAlias, ILogger logger)
{
var contentType = Current.Services.MediaTypeService.Get(media.ContentTypeId);
var propertyType = contentType.PropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyAlias));
if (propertyType == null) return string.Empty;
var val = media.Properties[propertyType];
if (val == null) return string.Empty;
if (!media.Properties.TryGetValue(propertyAlias, out var property))
return string.Empty;
// TODO: would need to be adjusted to variations, when media become variants
var jsonString = val.GetValue() as string;
var jsonString = property?.GetValue() as string;
if (jsonString == null) return string.Empty;
if (propertyType.PropertyEditorAlias == Constants.PropertyEditors.Aliases.UploadField)
if (property.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.Aliases.UploadField)
return jsonString;
if (propertyType.PropertyEditorAlias == Constants.PropertyEditors.Aliases.ImageCropper)
if (property.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.Aliases.ImageCropper)
{
if (jsonString.DetectIsJson() == false)
return jsonString;