You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System;using Umbraco.Cms.Core;using Umbraco.Cms.Core.Models.PublishedContent;using Umbraco.Cms.Core.PropertyEditors;using Umbraco.Cms.Core.PublishedCache;using Umbraco.Extensions;namespace MyConverters;publicclass ContentPickerPropertyConverter :IPropertyValueConverter{privatereadonlyIPublishedSnapshotAccessor_publishedSnapshotAccessor;//Injecting the PublishedSnapshotAccessor for fetching contentpublicContentPickerPropertyConverter(IPublishedSnapshotAccessorpublishedSnapshotAccessor){_publishedSnapshotAccessor=publishedSnapshotAccessor;}publicboolIsConverter(IPublishedPropertyTypepropertyType){return propertyType.EditorAlias.Equals("Umbraco.ContentPicker");}publicbool?IsValue(objectvalue,PropertyValueLevellevel){switch(level){case PropertyValueLevel.Source:returnvalue!=null&&(!(value isstring)||string.IsNullOrWhiteSpace((string) value)==false);default:thrownew NotSupportedException($"Invalid level: {level}.");}}public Type GetPropertyValueType(IPublishedPropertyTypepropertyType){returntypeof(IPublishedContent);}public PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyTypepropertyType){return PropertyCacheLevel.Elements;}publicobjectConvertSourceToIntermediate(IPublishedElementowner,IPublishedPropertyTypepropertyType,objectsource,boolpreview){if(source==null)returnnull;varattemptConvertInt= source.TryConvertTo<int>();if(attemptConvertInt.Success)return attemptConvertInt.Result;varattemptConvertUdi= source.TryConvertTo<Udi>();if(attemptConvertUdi.Success)return attemptConvertUdi.Result;returnnull;}publicobjectConvertIntermediateToObject(IPublishedElementowner,IPublishedPropertyTypepropertyType,PropertyCacheLevelreferenceCacheLevel,objectinter,boolpreview){if(inter==null)returnnull;if((propertyType.Alias !=null)==false){IPublishedContentcontent;if(inter isint id){content= _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(id);if(content!=null)returncontent;}else{varudi= inter as GuidUdi;if(udi==null)returnnull;content= _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(udi.Guid);if(content!=null&& content.ContentType.ItemType == PublishedItemType.Content)returncontent;}}returninter;}publicobjectConvertIntermediateToXPath(IPublishedElementowner,IPublishedPropertyTypepropertyType,PropertyCacheLevelreferenceCacheLevel,objectinter,boolpreview){if(inter==null)returnnull;return inter.ToString();}}{% hint style="warning"%}
The current implementation of XPath is suboptimal and will be removed entirely in a future version. It is currently obsolete and scheduled for removal in v14.{% endhint %}