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

67 lines
3.0 KiB
C#
Raw Normal View History

2019-03-26 10:39:50 +01:00
using Umbraco.Core.Logging;
using Umbraco.Core.Mapping;
2018-06-29 19:52:40 +02:00
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Creates a ContentPropertyDisplay from a Property
/// </summary>
2019-03-26 10:39:50 +01:00
internal class ContentPropertyDisplayMapper : ContentPropertyBasicMapper<ContentPropertyDisplay>
2018-06-29 19:52:40 +02:00
{
private readonly ILocalizedTextService _textService;
public ContentPropertyDisplayMapper(IDataTypeService dataTypeService, IEntityService entityService, ILocalizedTextService textService, ILogger logger, PropertyEditorCollection propertyEditors)
: base(dataTypeService, entityService, logger, propertyEditors)
2018-06-29 19:52:40 +02:00
{
_textService = textService;
}
2019-03-26 18:47:35 +01:00
public override void Map(Property originalProp, ContentPropertyDisplay dest, MapperContext context)
2018-06-29 19:52:40 +02:00
{
2019-03-26 18:47:35 +01:00
base.Map(originalProp, dest, context);
2018-06-29 19:52:40 +02:00
var config = DataTypeService.GetDataType(originalProp.PropertyType.DataTypeId).Configuration;
// TODO: IDataValueEditor configuration - general issue
2018-06-29 19:52:40 +02:00
// GetValueEditor() returns a non-configured IDataValueEditor
// - for richtext and nested, configuration determines HideLabel, so we need to configure the value editor
// - could configuration also determines ValueType, everywhere?
// - does it make any sense to use a IDataValueEditor without configuring it?
// configure the editor for display with configuration
2019-03-26 18:47:35 +01:00
var valEditor = dest.PropertyEditor.GetValueEditor(config);
2018-06-29 19:52:40 +02:00
//set the display properties after mapping
2019-03-26 18:47:35 +01:00
dest.Alias = originalProp.Alias;
dest.Description = originalProp.PropertyType.Description;
dest.Label = originalProp.PropertyType.Name;
dest.HideLabel = valEditor.HideLabel;
2018-06-29 19:52:40 +02:00
//add the validation information
2019-03-26 18:47:35 +01:00
dest.Validation.Mandatory = originalProp.PropertyType.Mandatory;
dest.Validation.Pattern = originalProp.PropertyType.ValidationRegExp;
2018-06-29 19:52:40 +02:00
2019-03-26 18:47:35 +01:00
if (dest.PropertyEditor == null)
2018-06-29 19:52:40 +02:00
{
//display.Config = PreValueCollection.AsDictionary(preVals);
//if there is no property editor it means that it is a legacy data type
// we cannot support editing with that so we'll just render the readonly value view.
2019-03-26 18:47:35 +01:00
dest.View = "views/propertyeditors/readonlyvalue/readonlyvalue.html";
2018-06-29 19:52:40 +02:00
}
else
{
//let the property editor format the pre-values
2019-03-26 18:47:35 +01:00
dest.Config = dest.PropertyEditor.GetConfigurationEditor().ToValueEditor(config);
dest.View = valEditor.View;
2018-06-29 19:52:40 +02:00
}
//Translate
2019-03-26 18:47:35 +01:00
dest.Label = _textService.UmbracoDictionaryTranslate(dest.Label);
dest.Description = _textService.UmbracoDictionaryTranslate(dest.Description);
2018-06-29 19:52:40 +02:00
}
}
}