Gets contextual culture server validation working

This commit is contained in:
Shannon
2018-08-02 20:00:35 +10:00
parent d926f1b3a2
commit 1f25847cd7
19 changed files with 254 additions and 142 deletions

View File

@@ -70,7 +70,7 @@ namespace Umbraco.Web.Models.Mapping
//a culture needs to be in the context for a property type that can vary
if (culture == null && property.PropertyType.VariesByCulture())
throw new InvalidOperationException($"No languageId found in mapping operation when one is required for the culture neutral property type {property.PropertyType.Alias}");
throw new InvalidOperationException($"No culture found in mapping operation when one is required for the culture variant property type {property.PropertyType.Alias}");
//set the culture to null if it's an invariant property type
culture = !property.PropertyType.VariesByCulture() ? null : culture;

View File

@@ -1,5 +1,6 @@
using System;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
@@ -17,15 +18,24 @@ namespace Umbraco.Web.Models.Mapping
: base(dataTypeService, logger, propertyEditors)
{ }
public override ContentPropertyDto Convert(Property originalProperty, ContentPropertyDto dest, ResolutionContext context)
public override ContentPropertyDto Convert(Property property, ContentPropertyDto dest, ResolutionContext context)
{
var propertyDto = base.Convert(originalProperty, dest, context);
var propertyDto = base.Convert(property, dest, context);
propertyDto.IsRequired = originalProperty.PropertyType.Mandatory;
propertyDto.ValidationRegExp = originalProperty.PropertyType.ValidationRegExp;
propertyDto.Description = originalProperty.PropertyType.Description;
propertyDto.Label = originalProperty.PropertyType.Name;
propertyDto.DataType = DataTypeService.GetDataType(originalProperty.PropertyType.DataTypeId);
propertyDto.IsRequired = property.PropertyType.Mandatory;
propertyDto.ValidationRegExp = property.PropertyType.ValidationRegExp;
propertyDto.Description = property.PropertyType.Description;
propertyDto.Label = property.PropertyType.Name;
propertyDto.DataType = DataTypeService.GetDataType(property.PropertyType.DataTypeId);
//Get the culture from the context which will be set during the mapping operation for each property
var culture = context.GetCulture();
//a culture needs to be in the context for a property type that can vary
if (culture == null && property.PropertyType.VariesByCulture())
throw new InvalidOperationException($"No culture found in mapping operation when one is required for the culture variant property type {property.PropertyType.Alias}");
propertyDto.Culture = culture;
return propertyDto;
}