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 7100 karma points c-trib
    Jan 23, 2017 @ 16:38
    Nicholas Westby
    0

    Manually Running Processors From DittoMultiProcessor?

    Matt suggests I create a processor which internally calls a few other processors: https://github.com/leekelleher/umbraco-ditto/issues/203#issuecomment-274447642

    Theoretically, that should be possible with a DittoMultiProcessor, as in this example that runs DittoArchetype followed by DittoDocTypeFactory: https://github.com/leekelleher/umbraco-ditto-labs/blob/develop/src/Our.Umbraco.Ditto.Archetype/ComponentModel/Processors/DittoMixedArchetypeAttribute.cs

    However, there is a problem with this approach:

    private static IEnumerable<DittoProcessorAttribute> GetProcessors()
    {
        return new DittoProcessorAttribute[]
        {
            new DittoArchetypeAttribute(),
            new DittoDocTypeFactoryAttribute()
        };
    }
    

    It's returning an array of processors. The reason that's a problem given Matt's suggestion is that this doesn't allow for any sort of conditional logic to run so that the array of processors can change.

    For example, if I wanted to avoid calling DittoDocTypeFactory depending on the value returned from DittoArchetype, I don't see a way to do that with a DittoMultiProcessor.

    Is there some other way of manually calling processors, checking the result, and then based on that result possibly calling further processors?

    Of course, if I'm only relying on processors I build, I can simply put the code for them in some central class that I can then call from multiple processors. However, that approach breaks down when I need to do things like call a built-in Ditto processor (or a processor from a third-party library of Ditto processors).

  • Matt Brailsford 4123 posts 22194 karma points MVP 9x c-trib
    Jan 23, 2017 @ 17:28
    Matt Brailsford
    0

    @Nicholas the example I give is not suggesting you use a MultiProcessor, the suggestion I give is to write a Processor that handles the entire logic and outputs the final result, thus not needing multiple processors and a convoluted chain.

    I'm a struggling a little to give you a succinct answer as your examples keep changing so I think I must be missing something. Can you give a real world example that you are right now having a problem with? If I can see the real world problem, I can give you a better answer.

    Matt

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jan 23, 2017 @ 17:54
    Nicholas Westby
    0

    the suggestion I give is to write a Processor that handles the entire logic and outputs the final result

    That is the part I'm trying to avoid. I would rather than reinvent the wheel (i.e., rebuild bigger processors when I should be able to reuse existing processors).

    Take this actual example from a code base I'm working on (I removed some irrelevant bits for brevity, such as other properties):

    public class FeatureGallery : Widget
    {
        [UmbracoProperty]
        [ConstructTranslationTerm(TermPrefix = "Feature Header - ")]
        [DictionaryTranslation]
        public string Header { get; set; }
    
        [UmbracoProperty("header")]
        [ConstructTranslationTerm(TermPrefix = "Feature View More Text - ")]
        [DictionaryTranslation]
        public string ViewMoreText { get; set; }
    }
    

    In Umbraco, the "Header" field is a drop down that contains a few values (i.e., you might anticipate that it's plain text, but it's not).

    For each of the two C# properties, here is what the processor chain is currently doing:

    1. Get the value of the "Header" drop down.
    2. Construct a dictionary term based on a static string and the value of "Header".
    3. Translate that constructed dictionary term into the current language.

    What I'd like to do is provide a fallback for one of those C# properties. In other words, the Header C# property will remain unchanged. However, I'd like the ViewMoreText C# property to be able to rely on two possible translations (i.e., it prefers "Feature View More Text - Feature", but will fallback to "View More Text").

    I realize I could build my own processor to do all the conditional stuff, but then it wouldn't be able to make use of the other processor that was already built. I further realize that since I built the other processor it would be fairly trivially easy for me to create a different processor that does the conditional stuff. However, I'm thinking down the road for when this fallback functionality becomes required again and I'm not so lucky to have written all the processors I'm making use of (or for my coworkers, who also didn't write the processors).

Please Sign in or register to post replies

Write your reply to:

Draft