diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs index 0bd51784bf..295cbdef66 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs @@ -82,24 +82,38 @@ namespace Umbraco.Core.Models.PublishedContent { var converters = PropertyValueConvertersResolver.Current.Converters.ToArray(); - // todo: remove Union() once we drop IPropertyEditorValueConverter support. - _converter = null; - foreach (var converter in converters.Union(GetCompatConverters()).Where(x => x.IsConverter(this))) - { - if (_converter == null) - { - _converter = converter; - } - else - { - throw new InvalidOperationException(string.Format("Type '{2}' cannot be an IPropertyValueConverter" - + " for property '{1}' of content type '{0}' because type '{3}' has already been detected as a converter" - + " for that property, and only one converter can exist for a property.", - ContentType.Alias, PropertyTypeAlias, - converter.GetType().FullName, _converter.GetType().FullName)); - } - } + var defaultConverters = converters + .Where(x => x.GetType().GetCustomAttribute(false) != null) + .ToArray(); + _converter = null; + + //get all converters for this property type + // todo: remove Union() once we drop IPropertyEditorValueConverter support. + var foundConverters = converters.Union(GetCompatConverters()).Where(x => x.IsConverter(this)).ToArray(); + if (foundConverters.Length == 1) + { + _converter = foundConverters[0]; + } + else if (foundConverters.Length > 1) + { + //more than one was found, we need to first figure out if one of these is an Umbraco default value type converter + var nonDefault = foundConverters.Except(defaultConverters).ToArray(); + if (nonDefault.Length > 1) + { + //this is not allowed, there cannot be more than 1 custom converter + throw new InvalidOperationException( + string.Format("Type '{2}' cannot be an IPropertyValueConverter" + + " for property '{1}' of content type '{0}' because type '{3}' has already been detected as a converter" + + " for that property, and only one converter can exist for a property.", + ContentType.Alias, PropertyTypeAlias, + nonDefault[1].GetType().FullName, nonDefault[0].GetType().FullName)); + } + + //there's only 1 custom converter registered that so use it + _converter = nonDefault[0]; + } + // get the cache levels, quietely fixing the inconsistencies (no need to throw, really) _sourceCacheLevel = GetCacheLevel(_converter, PropertyCacheValue.Source); _objectCacheLevel = GetCacheLevel(_converter, PropertyCacheValue.Object); diff --git a/src/Umbraco.Core/PropertyEditors/DefaultPropertyValueConverterAttribute.cs b/src/Umbraco.Core/PropertyEditors/DefaultPropertyValueConverterAttribute.cs new file mode 100644 index 0000000000..4857e2bb07 --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/DefaultPropertyValueConverterAttribute.cs @@ -0,0 +1,12 @@ +using System; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// Indicates that this is a default property value converter (shipped with Umbraco) + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + internal class DefaultPropertyValueConverterAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs index 1156f6aca3..e5ed8b8b94 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs @@ -6,6 +6,13 @@ using Umbraco.Core.Models.PublishedContent; namespace Umbraco.Core.PropertyEditors.ValueConverters { + /// + /// The default converter for all property editors that expose a JSON value type + /// + /// + /// Since this is a default (umbraco) converter it will be ignored if another converter found conflicts with this one. + /// + [DefaultPropertyValueConverter] [PropertyValueType(typeof(JToken))] [PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)] public class JsonValueConverter : PropertyValueConverterBase diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 0f8de9761a..cdc083c264 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -331,6 +331,7 @@ +