Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event System: How to know if editor clicked Save or Save & Close?

Tags:

tridion

In Tridion 2011 SP1 I'm trying to implement an event that will publish items automatically whenever the editor presses Save & Close (but not Save).

Under normal conditions this could be handled in a CheckIn event, but because this item will probably be in workflow, there is no CheckIn event (yet).

In COM Events we had a flag (doneEditing) to tell us if the editor had pressed save & close vs Save. I don't seem to be able to find a similar option in TOM.NET Events.

For reference - here's the code so far:

[TcmExtension("Publish to Wip Events")]
public class PublishToWip : TcmExtension
{
    public PublishToWip()
    {
        EventSystem.SubscribeAsync<VersionedItem, SaveEventArgs>(PublishItemToWip, EventPhases.TransactionCommitted);
    }
    private void PublishItemToWip(VersionedItem item, SaveEventArgs args, EventPhases phases)
    {
       // Magic goes here
    }
}

I've looked at the options for SaveEventArgs, but haven't found anything that would provide me this information. Any tips?

like image 373
Nuno Linhares Avatar asked Apr 11 '12 20:04

Nuno Linhares


1 Answers

Alright, with some help from the CM team I got the right answer to this.

Use the CheckInEvent instead of save. Even if the item is in workflow it will still invoke this event when you click Save & Close (and only if you click Save & Close, not when you click Save).

Something like this will get me going:

[TcmExtension("Publish to Wip Events")]
public class PublishToWip : TcmExtension
{
    public PublishToWip()
    {
        EventSystem.Subscribe<VersionedItem, CheckInEventArgs>
            (PublishItemToWip, EventPhases.Processed);
    }
    private void PublishItemToWip(VersionedItem item, 
        CheckInEventArgs args, EventPhases phases)
    {

        if (!item.LockType.HasFlag(LockType.InWorkflow)) return;

        if (!item.IsCheckedOut) return;
        // do something now
like image 95
Nuno Linhares Avatar answered Oct 23 '22 03:10

Nuno Linhares