Moved Models from Umbraco.Core to Umbraco.Infrastructure
This commit is contained in:
30
src/Umbraco.Infrastructure/Models/ContentBaseExtensions.cs
Normal file
30
src/Umbraco.Infrastructure/Models/ContentBaseExtensions.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Strings
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides extension methods to IContentBase to get url segments.
|
||||
/// </summary>
|
||||
public static class ContentBaseExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the url segment for a specified content and culture.
|
||||
/// </summary>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="culture">The culture.</param>
|
||||
/// <param name="urlSegmentProviders"></param>
|
||||
/// <returns>The url segment.</returns>
|
||||
public static string GetUrlSegment(this IContentBase content, IShortStringHelper shortStringHelper, IEnumerable<IUrlSegmentProvider> urlSegmentProviders, string culture = null)
|
||||
{
|
||||
if (content == null) throw new ArgumentNullException(nameof(content));
|
||||
if (urlSegmentProviders == null) throw new ArgumentNullException(nameof(urlSegmentProviders));
|
||||
|
||||
var url = urlSegmentProviders.Select(p => p.GetUrlSegment(content, culture)).FirstOrDefault(u => u != null);
|
||||
url = url ?? new DefaultUrlSegmentProvider(shortStringHelper).GetUrlSegment(content, culture); // be safe
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user