4

I am writing a processor for the <addFromTemplate> pipeline. I noticed the following code in a number of the examples

  1. var item = args.FallbackProvider.AddFromTemplate(args.ItemName, args.TemplateId, args.Destination, args.NewId);
  2. args.ProcessorItem = args.Result = item;

What do 1 and 2 do?

1 Answer 1

2

When you write an <addFromTemplate> pipeline processor, you are actually replacing the default behavior of the ItemProvider.AddFromTemplate method. Every ItemProvider pipeline sends in the native ItemProvider as the args.FallbackProvider. As such, when you call the following, what you are actually doing is analogous to base.AddFromTemplate, wherein you are calling the native logic within your "overriding" (sort of - this isn't really the right term) method:

// analogous to base.AddFromTemplate
var item = args.FallbackProvider.AddFromTemplate(args.ItemName, args.TemplateId, args.Destination, args.NewId);

Since you are writing a processor, the only way to return a result is by setting a property on your Pipeline arguments. As such, we "return" (sort of - again, this isn't really the right term) a result by setting the args.Result property. Additionally, if there are any other processors then they should use the "result" of this processor instead of the item this processor started with as the args.ProcessorItem:

args.ProcessorItem =    // any other processors should use this item
    args.Result = item; // this is the result

More Information:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.