Not all PVCs return a correct XPath value
See original GitHub issueIn Umbraco 7 I’m using the following XPath query to fetch the ‘Not found’ error page: //error[statusCode='404']
, where the statusCode
property is selected from a dropdown (Umbraco.DropDown.Flexible
, enable multiple choice disabled and prevalues: 404
and 500
).
This XPath query doesn’t work anymore in Umbraco 8, although //error
does (so it’s something with the statusCode='505'
part). After checking the source of FlexibleDropdownPropertyValueConverter
, it always returns System.String[]
(the literal string value) as XPath value, because the intermediate value is a string[]
:
And the XPath value is returned from PropertyValueConverterBase
by just doing a ToString()
on it:
https://github.com/umbraco/Umbraco-CMS/blob/3bfd9b71e290354744d677440983ecd06c5c0788/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs#L45-L46
Looking at some other Property Value Converters, these all seem to return wrong XPath values:
FlexibleDropdownPropertyValueConverter
returnsSystem.String[]
instead of the comma seperated valuesMediaPickerValueConverter
returnsUmbraco.Core.Udi[]
instead of the comma seperated UDI valuesMultiNodeTreePickerValueConverter
returnsUmbraco.Core.Udi[]
instead of the comma seperated UDI values
Reproduction
Bug summary
UmbracoContext.Cache.GetByXPath("//error[statusCode='404']")
does not return content, because the XPath value from the FlexibleDropdownPropertyValueConverter
isn’t 404
, but System.String[]
.
Specifics
Latest version: Umbraco 8.1.5
Steps to reproduce
- Create a document type with alias
error
- Add a property
statusCode
usingUmbraco.DropDown.Flexible
, enable multiple choice disabled and prevalue:404
- Add content using the document type, select 404 in the dropdown, publish
- Try to query by XPath:
//error[statusCode='404']
Expected result
Return the content matched by the XPath query.
Actual result
Nothing returned, as the statusCode
value doesn’t match.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (9 by maintainers)
Methods:
IPropertyValueConverter.ConvertIntermediateToXPath(...)
converts the “intermediate” value into an XPath value (a string or an Xml fragment, more on this later) - this is where the actual work happens.IPublishedPropertyType.ConvertInterToXPath(...)
uses the above method from the converter for that type to convert the “intermediate” value into the XPath value, and manages the caching of the result.IPublishedProperty.GetXPathValue(...)
returns the XPath value (a string or an Xml fragment) of a property - which is obtained via the above methods.Which means that the only thing you need to bother implementing is the first one, the rest is plumbing that you should not need to bother about.
The method can return either a string, which will then be the property value in the Xml view of the cache, eg
<firstName>John</firstName>
. But it can also return an Xml fragment, as anXPathNavigator
. TheMultipleTextStringValueConverter
in Core implements such a conversion, and returns something that, in the Xml view of the cache, will look likeYup, valid comment about returning
values
or not - and then, only the elements. Glad it works!