leekelleher on develop
Migration to UMCO - Updated th… (compare)
@BarryFogarty If you use a base class for all your nested content you can decorate that class with [DittoDocTypeFactory]
Using it in any calling classes like
public virtual IEnumerable<NestedComponent> NestedContent { get; set; }
Will populate the values without having to declare any other attributes since Ditto will see no attributes and automatically add UmbracoProperty
Ok so the current logic is.
As long as the processor ones resolve to your expected type they should overule anything found elsewhere.... Should.
[UmbracoProperty("cards_Items", Order = 1)]
[UmbracoPicker(Order = 2)]
[DittoDocTypeFactory(Order = 3)]
public virtual IEnumerable<ICard> Items { get; set; }
public class XPathAttribute : DittoProcessorAttribute
{
private readonly string[] _currentItemIdentifiers = { ".", "$current" };
private readonly string[] _currentSiteIdentifiers = { "$site" };
private readonly string[] _currentPageIdentifiers = { "$currentPage" };
private string _xPath;
public XPathAttribute(string xPath)
{
_xPath = xPath;
}
public override object ProcessValue()
{
var umbracoContext = UmbracoContext.Current;
foreach (var currentItemIdentifier in _currentItemIdentifiers)
{
if (_xPath.StartsWith(currentItemIdentifier))
_xPath = $"id({Context.Content.Id})" + _xPath.Remove(0, currentItemIdentifier.Length).EnsureStartsWith("/");
}
foreach (var currentPageIdentifier in _currentPageIdentifiers)
{
if (_xPath.StartsWith(currentPageIdentifier))
_xPath = $"id({umbracoContext.PageId})" + _xPath.Remove(0, currentPageIdentifier.Length).EnsureStartsWith("/");
}
foreach (var currentSiteIdentifier in _currentSiteIdentifiers)
{
if (_xPath.StartsWith(currentSiteIdentifier))
_xPath = $"id({Context.Content.Id})/ancestor-or-self::*[@level = 1]" + _xPath.Remove(0, currentSiteIdentifier.Length).EnsureStartsWith("/");
}
if (Context.PropertyDescriptor.PropertyType.IsEnumerableType())
{
var genericTypeDefinition =
Context.PropertyDescriptor.PropertyType.GetGenericArguments().FirstOrDefault();
return umbracoContext.ContentCache.GetByXPath(_xPath).As(genericTypeDefinition);
}
return umbracoContext.ContentCache.GetSingleByXPath(_xPath).As(Context.PropertyDescriptor.PropertyType);
}
}