Starts wiring up the back office to the c# bits, updates controllers, mappers, models, property editors to support getting and saving data by language. The content editor now "works" with multi-lingual properties

This commit is contained in:
Shannon
2018-04-04 01:59:51 +10:00
parent e7bc4986a5
commit 7a73175aa0
39 changed files with 463 additions and 203 deletions

View File

@@ -3,9 +3,11 @@ using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Web.Composing;
using Umbraco.Web.Models.ContentEditing;
using ContentVariation = Umbraco.Core.Models.ContentVariation;
namespace Umbraco.Web.Models.Mapping
{
@@ -15,10 +17,14 @@ namespace Umbraco.Web.Models.Mapping
internal class ContentPropertyBasicConverter<TDestination> : ITypeConverter<Property, TDestination>
where TDestination : ContentPropertyBasic, new()
{
private readonly ILogger _logger;
private readonly PropertyEditorCollection _propertyEditors;
protected IDataTypeService DataTypeService { get; }
public ContentPropertyBasicConverter(IDataTypeService dataTypeService)
public ContentPropertyBasicConverter(IDataTypeService dataTypeService, ILogger logger, PropertyEditorCollection propertyEditors)
{
_logger = logger;
_propertyEditors = propertyEditors;
DataTypeService = dataTypeService;
}
@@ -28,19 +34,28 @@ namespace Umbraco.Web.Models.Mapping
/// <returns></returns>
public virtual TDestination Convert(Property property, TDestination dest, ResolutionContext context)
{
var editor = Current.PropertyEditors[property.PropertyType.PropertyEditorAlias];
var editor = _propertyEditors[property.PropertyType.PropertyEditorAlias];
if (editor == null)
{
Current.Logger.Error<ContentPropertyBasicConverter<TDestination>>(
_logger.Error<ContentPropertyBasicConverter<TDestination>>(
"No property editor found, converting to a Label",
new NullReferenceException("The property editor with alias " + property.PropertyType.PropertyEditorAlias + " does not exist"));
editor = Current.PropertyEditors[Constants.PropertyEditors.Aliases.NoEdit];
editor = _propertyEditors[Constants.PropertyEditors.Aliases.NoEdit];
}
var languageId = context.GetLanguageId();
if (!languageId.HasValue && property.PropertyType.Variations == ContentVariation.CultureNeutral)
{
//a language Id needs to be set for a property type that can be varried by language
throw new InvalidOperationException($"No languageId found in mapping operation when one is required for the culture neutral property type {property.PropertyType.Alias}");
}
var result = new TDestination
{
Id = property.Id,
Value = editor.GetValueEditor().ToEditor(property, DataTypeService),
Value = editor.GetValueEditor().ToEditor(property, DataTypeService, languageId),
Alias = property.Alias,
PropertyEditor = editor,
Editor = editor.Alias