Here's the short version of what I'm trying to accomplish:
[DataContentAs]
public class DealerOverview : Widget
{
[UmbracoProperty]
public string Overview { get; set; }
}
It doesn't seem to be working (still troubleshooting why), as the breakpoint in DataContentAsAttribute.ProcessValue never gets hit. Before I dig too deeply into this, I just wanted to check if Ditto is supposed to support class-level processors, or if it only supports property-level processors.
The DataContentAs will function similar to the existing CurrentContentAs in that it will change the value passed to the subsequent processor. In my case, it will choose one of multiple possible content nodes to be mapped (I have one content node used to map widgets, and another to map data). I'd like to avoid having to type this processor on each property and instead apply it once to the class.
Is it possible to create a class-level processor in Ditto?
[DittoLazy]
[UmbracoPicker]
public class Page : IEntity, IMeta, IXmlSitemap, IUrl, INavigation
{
public virtual string Name { get; set; }
}
Seems similar to my code, so I'm not sure why I was having issues. Perhaps because my class is being instantiated by the DittoDocTypeFactory processor (I'm mapping a bunch of heterogeneous widgets), which may be causing it to lose the ability to run a class-level processor.
I'll take a look soon; sounds like I might need to submit a bug report.
Strange, still doesn't seem to work for me. We are doing similar things, but not quite the same. I'll add the code I'm using below (minus the irrelevant bits).
Here's the model for my page:
public class Typical
{
/// <summary>
/// The main content for the page (a collection of widgets).
/// </summary>
[LocalizedUmbracoProperty]
[DittoMixedArchetype]
public IEnumerable<IWidget> MainContent { get; set; }
}
Here is one of my widgets:
[InspectValue]
public class DealerOverview : Widget
{
[UmbracoProperty]
[RemoveParagraph]
public string OverviewTitle { get; set; }
}
Here's the implementing of the InspectValue processor:
/// <summary>
/// This processor returns the value it was supplied.
/// </summary>
/// <remarks>
/// This processor can be used to set a breakpoint to inspect the output of a
/// previous processor.
/// </remarks>
[AttributeUsage(validOn: AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = true)]
public class InspectValueAttribute : UmbracoPropertyAttribute
{
/// <summary>
/// Returns the supplied value.
/// </summary>
/// <returns>
/// The supplied value.
/// </returns>
public override object ProcessValue()
{
// Set a breakpoint in this method to inspect the value.
var value = this.Value;
return value;
}
}
When I set a breakpoint on the above line (var value = this.Value;), that breakpoint is not hit. Any ideas why that might be?
One thought I have is that maybe Ditto doesn't like that I am decorating both Typical.MainContent and DealerOverview with processor attributes (i.e., maybe Ditto only expects one or the other to be decorated).
Does Ditto Support Class-Level Processors?
Here's the short version of what I'm trying to accomplish:
It doesn't seem to be working (still troubleshooting why), as the breakpoint in
DataContentAsAttribute.ProcessValue
never gets hit. Before I dig too deeply into this, I just wanted to check if Ditto is supposed to support class-level processors, or if it only supports property-level processors.The
DataContentAs
will function similar to the existingCurrentContentAs
in that it will change the value passed to the subsequent processor. In my case, it will choose one of multiple possible content nodes to be mapped (I have one content node used to map widgets, and another to map data). I'd like to avoid having to type this processor on each property and instead apply it once to the class.Is it possible to create a class-level processor in Ditto?
Hi Nicholas,
Ditto does support class level processors, in fact, I'd recommend using them to avoid bloat your codebase with attributes.
I've got some code online where I'm using them here https://github.com/JimBobSquarePants/Zoombraco
Cheers
James
Thanks for the confirmation. I can see for example that you are using class-level processors here: https://github.com/JimBobSquarePants/Zoombraco/blob/develop/src/Zoombraco/Models/DocumentTypes/Page.cs
Seems similar to my code, so I'm not sure why I was having issues. Perhaps because my class is being instantiated by the DittoDocTypeFactory processor (I'm mapping a bunch of heterogeneous widgets), which may be causing it to lose the ability to run a class-level processor.
I'll take a look soon; sounds like I might need to submit a bug report.
DittoDocTypeFactory shouldn't be an issue. Here's an example using it to wire up nested content, all heterogeneous.
Declaration https://github.com/JimBobSquarePants/Zoombraco/blob/develop/src/Zoombraco/Models/DocumentTypes/NestedComponent.cs
Implementation https://github.com/JimBobSquarePants/Zoombraco/blob/develop/tests/ZoombracoDemo.Logic/Models/Pages/Generic.cs
Strange, still doesn't seem to work for me. We are doing similar things, but not quite the same. I'll add the code I'm using below (minus the irrelevant bits).
Here's the model for my page:
Here is one of my widgets:
Here's the implementing of the
InspectValue
processor:When I set a breakpoint on the above line (
var value = this.Value;
), that breakpoint is not hit. Any ideas why that might be?One thought I have is that maybe Ditto doesn't like that I am decorating both
Typical.MainContent
andDealerOverview
with processor attributes (i.e., maybe Ditto only expects one or the other to be decorated).is working on a reply...