using Microsoft.Extensions.Logging; using Umbraco.Cms.Core.Dictionary; using Umbraco.Cms.Core.Mapping; using Umbraco.Cms.Core.Models.ContentEditing; using Umbraco.Cms.Core.PropertyEditors; using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.Models.Mapping { /// /// A mapper which declares how to map content properties. These mappings are shared among media (and probably members) which is /// why they are in their own mapper /// public class ContentPropertyMapDefinition : IMapDefinition { private readonly ContentPropertyBasicMapper _contentPropertyBasicConverter; private readonly ContentPropertyDtoMapper _contentPropertyDtoConverter; private readonly ContentPropertyDisplayMapper _contentPropertyDisplayMapper; public ContentPropertyMapDefinition(ICultureDictionary cultureDictionary, IDataTypeService dataTypeService, IEntityService entityService, ILocalizedTextService textService, ILoggerFactory loggerFactory, PropertyEditorCollection propertyEditors) { _contentPropertyBasicConverter = new ContentPropertyBasicMapper(dataTypeService, entityService, loggerFactory.CreateLogger>(), propertyEditors); _contentPropertyDtoConverter = new ContentPropertyDtoMapper(dataTypeService, entityService, loggerFactory.CreateLogger(), propertyEditors); _contentPropertyDisplayMapper = new ContentPropertyDisplayMapper(cultureDictionary, dataTypeService, entityService, textService, loggerFactory.CreateLogger(), propertyEditors); } public void DefineMaps(IUmbracoMapper mapper) { mapper.Define>((source, context) => new Tab(), Map); mapper.Define((source, context) => new ContentPropertyBasic(), Map); mapper.Define((source, context) => new ContentPropertyDto(), Map); mapper.Define((source, context) => new ContentPropertyDisplay(), Map); } // Umbraco.Code.MapAll -Properties -Alias -Expanded private void Map(PropertyGroup source, Tab target, MapperContext mapper) { target.Id = source.Id; target.Key = source.Key; target.Type = source.Type.ToString(); target.Label = source.Name; target.Alias = source.Alias; target.IsActive = true; } private void Map(IProperty source, ContentPropertyBasic target, MapperContext context) { // assume this is mapping everything and no MapAll is required _contentPropertyBasicConverter.Map(source, target, context); } private void Map(IProperty source, ContentPropertyDto target, MapperContext context) { // assume this is mapping everything and no MapAll is required _contentPropertyDtoConverter.Map(source, target, context); } private void Map(IProperty source, ContentPropertyDisplay target, MapperContext context) { // assume this is mapping everything and no MapAll is required _contentPropertyDisplayMapper.Map(source, target, context); } } }