From 2fcabdee0ac03497d01924ef3f46661a1aa67647 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Mon, 10 Sep 2018 09:09:24 +0100 Subject: [PATCH] Use ResolutionContext as opposed to an inline AfterMap function with a CustomResolver class --- src/Umbraco.Web/Editors/ContentController.cs | 4 ++-- .../Models/Mapping/ContentMapperProfile.cs | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index af79e04f2b..d5becce929 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -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); } diff --git a/src/Umbraco.Web/Models/Mapping/ContentMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/ContentMapperProfile.cs index 3c8a33c625..7d3f3cb63e 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentMapperProfile.cs @@ -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()); //FROM IContent TO ContentPropertyCollectionDto //NOTE: the property mapping for cultures relies on a culture being set in the mapping context CreateMap(); } } + + internal class CultureNameResolver : IValueResolver, string> + { + public string Resolve(IContent source, ContentItemBasic destination, string destMember, ResolutionContext context) + { + return source.GetCultureName(context.GetCulture()); + } + } }