From 56cd1cee81b18caef8a66da3ba4fef8c03ed59e5 Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 30 Jan 2014 15:07:43 +0100 Subject: [PATCH] U4-4160 - make sure string properties are returned as strings --- .../MustBeStringValueConverter.cs | 38 +++++++++++++++++++ src/Umbraco.Core/Umbraco.Core.csproj | 1 + .../MntpStringValueConverter.cs | 29 -------------- src/Umbraco.Web/Umbraco.Web.csproj | 1 - 4 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 src/Umbraco.Core/PropertyEditors/ValueConverters/MustBeStringValueConverter.cs delete mode 100644 src/Umbraco.Web/PropertyEditors/ValueConverters/MntpStringValueConverter.cs diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MustBeStringValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MustBeStringValueConverter.cs new file mode 100644 index 0000000000..45563d11e8 --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MustBeStringValueConverter.cs @@ -0,0 +1,38 @@ +using System.Linq; +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Core.PropertyEditors.ValueConverters +{ + /// + /// Ensures that no matter what is selected in (editor), the value results in a string. + /// + /// + /// For more details see issues http://issues.umbraco.org/issue/U4-3776 (MNTP) + /// and http://issues.umbraco.org/issue/U4-4160 (media picker). + /// The cache level is set to .Content because the string is supposed to depend + /// on the source value only, and not on any other content. It is NOT appropriate + /// to use that converter for values whose .ToString() would depend on other content. + /// + [DefaultPropertyValueConverter] + [PropertyValueType(typeof(string))] + [PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)] + public class MustBeStringValueConverter : PropertyValueConverterBase + { + private static readonly string[] Aliases = + { + Constants.PropertyEditors.MultiNodeTreePickerAlias, + Constants.PropertyEditors.MultipleMediaPickerAlias + }; + + public override bool IsConverter(PublishedPropertyType propertyType) + { + return Aliases.Contains(propertyType.PropertyEditorAlias); + } + + public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) + { + if (source == null) return null; + return source.ToString(); + } + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 18cd086cbe..f29a9f5b29 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -368,6 +368,7 @@ + diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MntpStringValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MntpStringValueConverter.cs deleted file mode 100644 index 14cc3a9b57..0000000000 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MntpStringValueConverter.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Umbraco.Core; -using Umbraco.Core.Models.PublishedContent; -using Umbraco.Core.PropertyEditors; - -namespace Umbraco.Web.PropertyEditors.ValueConverters -{ - /// - /// Ensures that no matter what is selected in MNTP that the value results in a string - /// - /// - /// See here for full details:http://issues.umbraco.org/issue/U4-3776 - /// - [DefaultPropertyValueConverter] - [PropertyValueType(typeof (string))] - [PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Request)] - public class MntpStringValueConverter : PropertyValueConverterBase - { - public override bool IsConverter(PublishedPropertyType propertyType) - { - return propertyType.PropertyEditorAlias == Constants.PropertyEditors.MultiNodeTreePickerAlias; - } - - public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) - { - if (source == null) return null; - return source.ToString(); - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index ce74fb02a8..a2b131709d 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -397,7 +397,6 @@ -