FIxes issue where an invariant property type was being validated with a culture when that would always fail. Fixes issue when saving a content type to ensure that a property type is never both variant and invariant. Adds test.

This commit is contained in:
Shannon
2018-05-10 18:01:41 +10:00
parent 8be861809a
commit f2b78c06ef
7 changed files with 115 additions and 31 deletions

View File

@@ -5,18 +5,18 @@ using ContentVariation = Umbraco.Core.Models.ContentVariation;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Returns the <see cref="ContentVariation"/> for a <see cref="PropertyType"/>
/// </summary>
internal class PropertyTypeVariationsResolver: IValueResolver<PropertyTypeBasic, PropertyType, ContentVariation>
{
public ContentVariation Resolve(PropertyTypeBasic source, PropertyType destination, ContentVariation destMember, ResolutionContext context)
{
//this will always be the case, a content type will always be allowed to be invariant
var result = ContentVariation.InvariantNeutral;
if (source.AllowCultureVariant)
{
result |= ContentVariation.CultureNeutral;
}
//A property type should only be one type of culture variation.
//If a property type allows both variant and invariant then it generally won't be able to save because validation
//occurs when performing something like IContent.TryPublishAllValues and it will result in validation problems because
//the invariant value will not be set since in the UI only the variant values are edited if it supports it.
var result = source.AllowCultureVariant ? ContentVariation.CultureNeutral : ContentVariation.InvariantNeutral;
return result;
}
}