Convert collections for XPath in PropertyValueConverterBase (#14275)

This commit is contained in:
Callum Whyte
2023-05-31 15:58:42 +01:00
committed by GitHub
parent 76cb85224e
commit e6903bffcd

View File

@@ -1,4 +1,6 @@
using Umbraco.Cms.Core.Models.PublishedContent;
using System.Collections.Generic;
using System.Xml;
using Umbraco.Cms.Core.Models.PublishedContent;
namespace Umbraco.Cms.Core.PropertyEditors;
@@ -48,7 +50,29 @@ public abstract class PropertyValueConverterBase : IPropertyValueConverter
/// <inheritdoc />
public virtual object? ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview)
=> inter?.ToString() ?? string.Empty;
{
var d = new XmlDocument();
XmlElement e = d.CreateElement("values");
d.AppendChild(e);
if (inter is IEnumerable<string> collection)
{
foreach (var value in collection)
{
XmlElement ee = d.CreateElement("value");
ee.InnerText = value;
e.AppendChild(ee);
}
}
else
{
XmlElement ee = d.CreateElement("value");
ee.InnerText = inter?.ToString() ?? string.Empty;
e.AppendChild(ee);
}
return d.CreateNavigator();
}
[Obsolete(
"This method is not part of the IPropertyValueConverter contract, therefore not used and will be removed in future versions; use IsValue instead.")]