Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to pass values from an SDL Tridion 2011 GUI Extension to the SaveEventArgs in an event handler

I am building a GUI extension using SDL Tridion 2011 SP1. I want to collect some user input when an editor hits a new "Save and Comment" button. This button will collect some user input, and then trigger the built in save commands of the CME.

Then using an Event Handler I would like to catch that user input, and do some custom processing with it. My simple event handler is as follows:

using System;
using System.Text;
using Tridion.ContentManager.Extensibility.Events;
using Tridion.ContentManager.Extensibility;
using Tridion.ContentManager.ContentManagement;
using System.IO;

namespace UrbanCherry.Net.SDLTridion.EventHandlers
{
  [TcmExtension("VersionCommenting")]
  public class VersionCommenting : TcmExtension
  {
    public VersionCommenting()
    {
      Subscribe();
    }

    public void Subscribe()
    {
      EventSystem.Subscribe<Component, SaveEventArgs>(AddCommentToItemVersion,
                                                      EventPhases.Initiated);
    }

    private void AddCommentToItemVersion(Component source, SaveEventArgs args,
                                         EventPhases phase)
    {
      //Do some work here   
    }
  }
}

Is it possible for my GUI extension to somehow add values to the SaveEventArgs, either using the args.ContextVariables or some other method?

like image 285
Chris Summers Avatar asked Nov 03 '22 21:11

Chris Summers


2 Answers

There is no direct way to pass parameters from a GUI extension to an event handler. So the only way I can imagine is by piggybacking the additional information into an existing data structure. Application data (as Will suggested) is one such data structure, but you can also consider piggybacking the information onto the existing Component XML.

Since you have both a GUI extension and an Event Handler, you essentially can do anything you want in the former, as long as you "undo" those changes in the latter.

So one way I can imagine:

  1. in your GUI extension, inject a custom element with the comment into the Component XML
  2. in your Event Handler, extract the comment and remove the custom element

I haven't tested this approach, but have done similar thing with custom Data Extenders: change the command or data sent to the server and then on the server detect that change and act on it (before passing it on to TCM).

Of course you'd have to make sure your event handler in this case removes the comment from the Component XML in one of the earlier phases.

If you want to do it safely you should take the comment off from the Component XML in a very early event phase and then only save the comment in the pre-commit/post-commit phase. In between those phases you'd have to store the comment somewhere, but at least the data made it from the GUI to the server by then.

like image 62
Frank van Puffelen Avatar answered Dec 02 '22 19:12

Frank van Puffelen


Just an idea, and no idea how to actually do it in the GUI Extension, but have you thought of setting the comment as Application Data on the item when you click the button?

like image 28
Will Avatar answered Dec 02 '22 18:12

Will