Refactor getting Urls

This commit is contained in:
Stephan
2019-04-24 11:53:35 +02:00
parent eb390f8d80
commit 25b8c8a565
6 changed files with 37 additions and 88 deletions

View File

@@ -145,7 +145,7 @@ namespace Umbraco.Web
}
#endregion
#region ToIndexedArray
public static IndexedArrayItem<TContent>[] ToIndexedArray<TContent>(this IEnumerable<TContent> source)
@@ -192,14 +192,19 @@ namespace Umbraco.Web
#region MediaUrl
/// <summary>
/// Gets the url for the media.
/// Gets the url for a media.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="propertyAlias">The property alias to resolve the url from.</param>
/// <param name="culture">The variation language.</param>
/// <returns>The url for the content.</returns>
/// <remarks>Better use the <c>GetMediaUrl</c> method but that method is here to complement <c>MediaUrlAbsolute()</c>.</remarks>
public static string MediaUrl(this IPublishedContent content, string propertyAlias, string culture = null)
/// <param name="content">The content item.</param>
/// <param name="culture">The culture (use current culture by default).</param>
/// <param name="mode">The url mode (use site configuration by default).</param>
/// <param name="propertyAlias">The alias of the property (use 'umbracoFile' by default).</param>
/// <returns>The url for the media.</returns>
/// <remarks>
/// <para>The value of this property is contextual. It depends on the 'current' request uri,
/// if any. In addition, when the content type is multi-lingual, this is the url for the
/// specified culture. Otherwise, it is the invariant url.</para>
/// </remarks>
public static string MediaUrl(this IPublishedContent content, string culture = null, UrlMode mode = UrlMode.Default, string propertyAlias = Constants.Conventions.Media.File)
{
var umbracoContext = Composing.Current.UmbracoContext;
@@ -208,27 +213,7 @@ namespace Umbraco.Web
if (umbracoContext.UrlProvider == null)
throw new InvalidOperationException("Cannot resolve a Url for a content item when Current.UmbracoContext.UrlProvider is null.");
return umbracoContext.UrlProvider.GetMediaUrl(content, propertyAlias, culture);
}
/// <summary>
/// Gets the absolute url for the media.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="propertyAlias">The property alias to resolve the url from.</param>
/// <param name="mode">The url mode.</param>
/// <param name="culture">The variation language.</param>
/// <returns>The absolute url for the media.</returns>
public static string MediaUrl(this IPublishedContent content, string propertyAlias, UrlMode mode, string culture = null)
{
var umbracoContext = Composing.Current.UmbracoContext;
if (umbracoContext == null)
throw new InvalidOperationException("Cannot resolve a Url for a content item when Current.UmbracoContext is null.");
if (umbracoContext.UrlProvider == null)
throw new InvalidOperationException("Cannot resolve a Url for a content item when Current.UmbracoContext.UrlProvider is null.");
return umbracoContext.UrlProvider.GetMediaUrl(content, propertyAlias, mode, culture);
return umbracoContext.UrlProvider.GetMediaUrl(content, mode, culture, propertyAlias);
}
#endregion