Files
Umbraco-CMS/src/Umbraco.Core/PropertyEditors/MediaUrlGeneratorCollection.cs
Zeegaan 1e20724882 Merge pull request #10676 from umbraco/v9/bugfix/image-upload
V9: Fix drag and drop image upload
2021-08-02 12:57:15 +02:00

38 lines
1.1 KiB
C#

using System.Collections.Generic;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Models;
namespace Umbraco.Cms.Core.PropertyEditors
{
public class MediaUrlGeneratorCollection : BuilderCollectionBase<IMediaUrlGenerator>
{
public MediaUrlGeneratorCollection(System.Func<IEnumerable<IMediaUrlGenerator>> items) : base(items)
{
}
public bool TryGetMediaPath(string propertyEditorAlias, object value, out string mediaPath)
{
// We can't get a media path from a null value
// The value will be null when uploading a brand new image, since we try to get the "old path" which doesn't exist yet.
if (value is null)
{
mediaPath = null;
return false;
}
foreach(IMediaUrlGenerator generator in this)
{
if (generator.TryGetMediaPath(propertyEditorAlias, value, out var mp))
{
mediaPath = mp;
return true;
}
}
mediaPath = null;
return false;
}
}
}