Use ResolutionContext as opposed to an inline AfterMap function with a CustomResolver class
This commit is contained in:
@@ -496,11 +496,11 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
if(string.IsNullOrEmpty(cultureName) == false)
|
||||
{
|
||||
opts.AfterMap((source, target) => target.Name = source.GetCultureName(cultureName));
|
||||
opts.Items[ResolutionContextExtensions.CultureKey] = cultureName;
|
||||
}
|
||||
|
||||
// if there's a list of property aliases to map - we will make sure to store this in the mapping context.
|
||||
if (String.IsNullOrWhiteSpace(includeProperties) == false)
|
||||
if (string.IsNullOrWhiteSpace(includeProperties) == false)
|
||||
{
|
||||
opts.Items["IncludeProperties"] = includeProperties.Split(new[] { ", ", "," }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
@@ -83,11 +83,20 @@ namespace Umbraco.Web.Models.Mapping
|
||||
.ForMember(dest => dest.Trashed, opt => opt.MapFrom(src => src.Trashed))
|
||||
.ForMember(dest => dest.ContentTypeAlias, opt => opt.MapFrom(src => src.ContentType.Alias))
|
||||
.ForMember(dest => dest.Alias, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.AdditionalData, opt => opt.Ignore());
|
||||
.ForMember(dest => dest.AdditionalData, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Name, opt => opt.ResolveUsing<CultureNameResolver>());
|
||||
|
||||
//FROM IContent TO ContentPropertyCollectionDto
|
||||
//NOTE: the property mapping for cultures relies on a culture being set in the mapping context
|
||||
CreateMap<IContent, ContentPropertyCollectionDto>();
|
||||
}
|
||||
}
|
||||
|
||||
internal class CultureNameResolver : IValueResolver<IContent, ContentItemBasic<ContentPropertyBasic>, string>
|
||||
{
|
||||
public string Resolve(IContent source, ContentItemBasic<ContentPropertyBasic> destination, string destMember, ResolutionContext context)
|
||||
{
|
||||
return source.GetCultureName(context.GetCulture());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user