Files
Umbraco-CMS/src/Umbraco.Web/Models/Mapping/MacroModelMapper.cs

53 lines
2.7 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2013-11-07 17:16:22 +01:00
using System.Linq;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Logging;
2013-11-07 17:16:22 +01:00
using Umbraco.Core.Models;
using Umbraco.Core.Models.Mapping;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Declares model mappings for macros.
/// </summary>
internal class MacroModelMapper : ModelMapperConfiguration
2013-11-07 17:16:22 +01:00
{
public override void ConfigureMappings(IMapperConfiguration config)
2013-11-07 17:16:22 +01:00
{
//FROM IMacro TO EntityBasic
config.CreateMap<IMacro, EntityBasic>()
2017-05-12 14:49:44 +02:00
.ForMember(x => x.Udi, expression => expression.MapFrom(content => Udi.Create(Constants.UdiEntityType.Macro, content.Key)))
2013-11-07 17:16:22 +01:00
.ForMember(entityBasic => entityBasic.Icon, expression => expression.UseValue("icon-settings-alt"))
.ForMember(dto => dto.ParentId, expression => expression.UseValue(-1))
.ForMember(dto => dto.Path, expression => expression.ResolveUsing(macro => "-1," + macro.Id))
2014-10-03 17:07:27 +10:00
.ForMember(dto => dto.Trashed, expression => expression.Ignore())
.ForMember(dto => dto.AdditionalData, expression => expression.Ignore());
2013-11-07 17:16:22 +01:00
config.CreateMap<IMacro, IEnumerable<MacroParameter>>()
.ConvertUsing(macro => macro.Properties.Select(Mapper.Map<MacroParameter>).ToList());
config.CreateMap<IMacroProperty, MacroParameter>()
.ForMember(x => x.View, expression => expression.Ignore())
.ForMember(x => x.Configuration, expression => expression.Ignore())
.ForMember(x => x.Value, expression => expression.Ignore())
.AfterMap((property, parameter) =>
{
//map the view and the config
2017-05-12 14:49:44 +02:00
// we need to show the depracated ones for backwards compatibility
var paramEditor = Current.ParameterEditors[property.EditorAlias]; // fixme - include/filter deprecated?!
if (paramEditor == null)
{
//we'll just map this to a text box
2016-08-18 10:02:46 +02:00
paramEditor = Current.ParameterEditors[Constants.PropertyEditors.TextboxAlias];
Current.Logger.Warn<MacroModelMapper>("Could not resolve a parameter editor with alias " + property.EditorAlias + ", a textbox will be rendered in it's place");
}
parameter.View = paramEditor.ValueEditor.View;
//set the config
parameter.Configuration = paramEditor.Configuration;
});
2013-11-07 17:16:22 +01:00
}
}
}