Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Jan 09, 2017 @ 20:19
    Nicholas Westby
    0

    Does Ditto Support Class-Level Processors?

    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?

  • James Jackson-South 489 posts 1747 karma points c-trib
    Jan 10, 2017 @ 00:23
    James Jackson-South
    0

    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

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Jan 10, 2017 @ 03:37
    Nicholas Westby
    0

    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

    [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.

  • James Jackson-South 489 posts 1747 karma points c-trib
    Jan 10, 2017 @ 04:09
    James Jackson-South
    0
  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Jan 10, 2017 @ 18:50
    Nicholas Westby
    0

    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).

Please Sign in or register to post replies

Write your reply to:

Draft