Gets the variant names working in the editor

This commit is contained in:
Shannon
2018-04-20 00:59:23 +10:00
parent d4252a3dc8
commit c84087e96b
8 changed files with 59 additions and 29 deletions

View File

@@ -0,0 +1,25 @@
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Web.Models.ContentEditing;
using ContentVariation = Umbraco.Core.Models.ContentVariation;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Used to map the <see cref="ContentItemDisplay"/> name from an <see cref="IContent"/> depending on it's variation settings
/// </summary>
internal class ContentItemDisplayNameResolver : IValueResolver<IContent, ContentItemDisplay, string>
{
public string Resolve(IContent source, ContentItemDisplay destination, string destMember, ResolutionContext context)
{
var langId = context.GetLanguageId();
if (langId.HasValue && source.ContentType.Variations.HasFlag(ContentVariation.CultureNeutral))
{
//return the culture name being requested
return source.GetName(langId);
}
return source.Name;
}
}
}