Skip to content

Commit 56cd1ce

Browse files
committed
U4-4160 - make sure string properties are returned as strings
1 parent 002988c commit 56cd1ce

File tree

4 files changed

+39
-30
lines changed

4 files changed

+39
-30
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Linq;
2+
using Umbraco.Core.Models.PublishedContent;
3+
4+
namespace Umbraco.Core.PropertyEditors.ValueConverters
5+
{
6+
/// <summary>
7+
/// Ensures that no matter what is selected in (editor), the value results in a string.
8+
/// </summary>
9+
/// <remarks>
10+
/// <para>For more details see issues http://issues.umbraco.org/issue/U4-3776 (MNTP)
11+
/// and http://issues.umbraco.org/issue/U4-4160 (media picker).</para>
12+
/// <para>The cache level is set to .Content because the string is supposed to depend
13+
/// on the source value only, and not on any other content. It is NOT appropriate
14+
/// to use that converter for values whose .ToString() would depend on other content.</para>
15+
/// </remarks>
16+
[DefaultPropertyValueConverter]
17+
[PropertyValueType(typeof(string))]
18+
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)]
19+
public class MustBeStringValueConverter : PropertyValueConverterBase
20+
{
21+
private static readonly string[] Aliases =
22+
{
23+
Constants.PropertyEditors.MultiNodeTreePickerAlias,
24+
Constants.PropertyEditors.MultipleMediaPickerAlias
25+
};
26+
27+
public override bool IsConverter(PublishedPropertyType propertyType)
28+
{
29+
return Aliases.Contains(propertyType.PropertyEditorAlias);
30+
}
31+
32+
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
33+
{
34+
if (source == null) return null;
35+
return source.ToString();
36+
}
37+
}
38+
}

src/Umbraco.Core/Umbraco.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@
368368
<Compile Include="PropertyEditors\ValueConverters\JsonValueConverter.cs" />
369369
<Compile Include="PropertyEditors\ValueConverters\MultipleTextStringValueConverter.cs" />
370370
<Compile Include="PropertyEditors\ValueConverters\MarkdownEditorValueConverter.cs" />
371+
<Compile Include="PropertyEditors\ValueConverters\MustBeStringValueConverter.cs" />
371372
<Compile Include="PropertyEditors\ValueConverters\TextStringValueConverter.cs" />
372373
<Compile Include="PropertyEditors\ValueConverters\TinyMceValueConverter.cs" />
373374
<Compile Include="PropertyEditors\IPropertyValueConverter.cs" />

src/Umbraco.Web/PropertyEditors/ValueConverters/MntpStringValueConverter.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Umbraco.Web/Umbraco.Web.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@
397397
<Compile Include="PropertyEditors\TagsPropertyEditor.cs" />
398398
<Compile Include="PropertyEditors\UploadFileTypeValidator.cs" />
399399
<Compile Include="PropertyEditors\UserPickerPropertyEditor.cs" />
400-
<Compile Include="PropertyEditors\ValueConverters\MntpStringValueConverter.cs" />
401400
<Compile Include="PropertyEditors\ValueConverters\RelatedLinksEditorValueConvertor.cs" />
402401
<Compile Include="PropertyEditors\ValueListPreValueEditor.cs" />
403402
<Compile Include="PropertyEditors\DropDownPropertyEditor.cs" />

0 commit comments

Comments
 (0)