2021-02-18 11:06:02 +01:00
|
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
|
// See LICENSE for more details.
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
|
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;
|
|
|
|
|
|
using Umbraco.Extensions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Core.Models.Mapping
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
/// <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
|
|
|
|
{
|
2019-11-22 13:13:19 +11:00
|
|
|
|
private readonly ICultureDictionary _cultureDictionary;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
private readonly ILocalizedTextService _textService;
|
|
|
|
|
|
|
2020-09-21 09:52:58 +02:00
|
|
|
|
public ContentPropertyDisplayMapper(ICultureDictionary cultureDictionary, IDataTypeService dataTypeService, IEntityService entityService, ILocalizedTextService textService, ILogger<ContentPropertyDisplayMapper> logger, PropertyEditorCollection propertyEditors)
|
2019-07-01 16:22:54 +10:00
|
|
|
|
: base(dataTypeService, entityService, logger, propertyEditors)
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
2019-11-22 13:13:19 +11:00
|
|
|
|
_cultureDictionary = cultureDictionary;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
_textService = textService;
|
|
|
|
|
|
}
|
2019-11-08 15:10:05 +01:00
|
|
|
|
public override void Map(IProperty 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;
|
|
|
|
|
|
|
2019-01-27 01:17:32 -05:00
|
|
|
|
// 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;
|
2020-10-01 17:30:03 +02:00
|
|
|
|
dest.LabelOnTop = originalProp.PropertyType.LabelOnTop;
|
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;
|
2019-06-26 14:37:02 +02:00
|
|
|
|
dest.Validation.MandatoryMessage = originalProp.PropertyType.MandatoryMessage;
|
2019-03-26 18:47:35 +01:00
|
|
|
|
dest.Validation.Pattern = originalProp.PropertyType.ValidationRegExp;
|
2019-06-26 14:37:02 +02:00
|
|
|
|
dest.Validation.PatternMessage = originalProp.PropertyType.ValidationRegExpMessage;
|
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-11-22 13:13:19 +11:00
|
|
|
|
dest.Label = _textService.UmbracoDictionaryTranslate(_cultureDictionary, dest.Label);
|
|
|
|
|
|
dest.Description = _textService.UmbracoDictionaryTranslate(_cultureDictionary, dest.Description);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|