U4-4160 - make sure string properties are returned as strings
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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" />
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user