Skip to content

Commit f1db403

Browse files
authored
Fix for issue 15598 (#15617)
* Make GetIndexValues virtual * First try get values as JSON. If empty, try as CSV.
1 parent e04c4a8 commit f1db403

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/Umbraco.Core/PropertyEditors/JsonPropertyIndexValueFactoryBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected JsonPropertyIndexValueFactoryBase(IJsonSerializer jsonSerializer): thi
4040

4141
}
4242

43-
public IEnumerable<KeyValuePair<string, IEnumerable<object?>>> GetIndexValues(
43+
public virtual IEnumerable<KeyValuePair<string, IEnumerable<object?>>> GetIndexValues(
4444
IProperty property,
4545
string? culture,
4646
string? segment,

src/Umbraco.Core/PropertyEditors/TagPropertyIndexValueFactory.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1+
using System.Text.Json;
12
using Microsoft.Extensions.DependencyInjection;
23
using Microsoft.Extensions.Options;
34
using Umbraco.Cms.Core.Configuration.Models;
45
using Umbraco.Cms.Core.Models;
56
using Umbraco.Cms.Core.Serialization;
67
using Umbraco.Cms.Web.Common.DependencyInjection;
8+
using Umbraco.Extensions;
79

810
namespace Umbraco.Cms.Core.PropertyEditors;
911

1012
public class TagPropertyIndexValueFactory : JsonPropertyIndexValueFactoryBase<string[]>, ITagPropertyIndexValueFactory
1113
{
14+
private IndexingSettings _indexingSettings;
15+
1216
public TagPropertyIndexValueFactory(
1317
IJsonSerializer jsonSerializer,
1418
IOptionsMonitor<IndexingSettings> indexingSettings)
1519
: base(jsonSerializer, indexingSettings)
1620
{
1721
ForceExplicitlyIndexEachNestedProperty = true;
22+
_indexingSettings = indexingSettings.CurrentValue;
23+
indexingSettings.OnChange(newValue => _indexingSettings = newValue);
1824
}
1925

2026
[Obsolete("Use non-obsolete constructor. This will be removed in Umbraco 14.")]
@@ -45,4 +51,40 @@ public TagPropertyIndexValueFactory(IJsonSerializer jsonSerializer)
4551
{
4652
yield return new KeyValuePair<string, IEnumerable<object?>>(property.Alias, deserializedPropertyValue);
4753
}
54+
55+
public override IEnumerable<KeyValuePair<string, IEnumerable<object?>>> GetIndexValues(
56+
IProperty property,
57+
string? culture,
58+
string? segment,
59+
bool published,
60+
IEnumerable<string> availableCultures,
61+
IDictionary<Guid, IContentType> contentTypeDictionary)
62+
{
63+
IEnumerable<KeyValuePair<string, IEnumerable<object?>>> jsonValues = base.GetIndexValues(property, culture, segment, published, availableCultures, contentTypeDictionary);
64+
if (jsonValues?.Any() is true)
65+
{
66+
return jsonValues;
67+
}
68+
69+
var result = new List<KeyValuePair<string, IEnumerable<object?>>>();
70+
71+
var propertyValue = property.GetValue(culture, segment, published);
72+
73+
// If there is a value, it's a string and it's not empty/white space
74+
if (propertyValue is string rawValue && !string.IsNullOrWhiteSpace(rawValue))
75+
{
76+
var values = rawValue.Split(',', StringSplitOptions.RemoveEmptyEntries);
77+
78+
result.AddRange(Handle(values, property, culture, segment, published, availableCultures, contentTypeDictionary));
79+
}
80+
81+
IEnumerable<KeyValuePair<string, IEnumerable<object?>>> summary = HandleResume(result, property, culture, segment, published);
82+
if (_indexingSettings.ExplicitlyIndexEachNestedProperty || ForceExplicitlyIndexEachNestedProperty)
83+
{
84+
result.AddRange(summary);
85+
return result;
86+
}
87+
88+
return summary;
89+
}
4890
}

0 commit comments

Comments
 (0)