U4-4160 - make sure string properties are returned as strings

This commit is contained in:
Stephan
2014-01-30 15:07:43 +01:00
parent 002988ce86
commit 56cd1cee81
4 changed files with 39 additions and 30 deletions

View File

@@ -0,0 +1,38 @@
using System.Linq;
using Umbraco.Core.Models.PublishedContent;
namespace Umbraco.Core.PropertyEditors.ValueConverters
{
/// <summary>
/// Ensures that no matter what is selected in (editor), the value results in a string.
/// </summary>
/// <remarks>
/// <para>For more details see issues http://issues.umbraco.org/issue/U4-3776 (MNTP)
/// and http://issues.umbraco.org/issue/U4-4160 (media picker).</para>
/// <para>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.</para>
/// </remarks>
[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();
}
}
}

View File

@@ -368,6 +368,7 @@
<Compile Include="PropertyEditors\ValueConverters\JsonValueConverter.cs" />
<Compile Include="PropertyEditors\ValueConverters\MultipleTextStringValueConverter.cs" />
<Compile Include="PropertyEditors\ValueConverters\MarkdownEditorValueConverter.cs" />
<Compile Include="PropertyEditors\ValueConverters\MustBeStringValueConverter.cs" />
<Compile Include="PropertyEditors\ValueConverters\TextStringValueConverter.cs" />
<Compile Include="PropertyEditors\ValueConverters\TinyMceValueConverter.cs" />
<Compile Include="PropertyEditors\IPropertyValueConverter.cs" />

View File

@@ -1,29 +0,0 @@
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors.ValueConverters
{
/// <summary>
/// Ensures that no matter what is selected in MNTP that the value results in a string
/// </summary>
/// <remarks>
/// See here for full details:http://issues.umbraco.org/issue/U4-3776
/// </remarks>
[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();
}
}
}

View File

@@ -397,7 +397,6 @@
<Compile Include="PropertyEditors\TagsPropertyEditor.cs" />
<Compile Include="PropertyEditors\UploadFileTypeValidator.cs" />
<Compile Include="PropertyEditors\UserPickerPropertyEditor.cs" />
<Compile Include="PropertyEditors\ValueConverters\MntpStringValueConverter.cs" />
<Compile Include="PropertyEditors\ValueConverters\RelatedLinksEditorValueConvertor.cs" />
<Compile Include="PropertyEditors\ValueListPreValueEditor.cs" />
<Compile Include="PropertyEditors\DropDownPropertyEditor.cs" />