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?
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:
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With