Event system: how to find out if the editor clicked Save or Save & Close?

In Tridion 2011 SP1, I am trying to implement an event that will publish items automatically when the editor clicks Save and Close (but not Save).

Under normal circumstances, this can be handled in the CheckIn event, but since this element is likely to be in the workflow, there is no CheckIn event yet.

In COM events, we had a flag (doneEditing) to tell us if the editor clicked save and close vs Save. It seems I can not find a similar option in TOM.NET events.

For reference - here is 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 looked at SaveEventArgs options, but did not find anything that would provide me with this information. Any tips?

+6
source share
3 answers

Well, with some help from the CM team, I got the correct answer to this.

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

Something like this will catch me:

 [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 
+5
source

I looked at this in the past, but did not find a suitable solution. In the end, I gave up.

The idea I had was to have a GUI extension to intercept Save, and as such write an AppData record for this element, saying it was Save or SaveClose. Then your event system will read AppData and act accordingly.

Remember to clear the AppData in the event code.

+2
source

To catch the finished workflow, you need to subscribe to the FinishProcess event in Process, and not to the component:

 EventSystem.SubscribeAsync<Process, FinishProcessEventArgs>(FinishProcessHandler, EventPhases.TransactionCommitted, EventSubscriptionOrder.Late); 

In the instance of the event handler, the handler will contain a list of objects with a completed workflow with the version you want to publish:

 private static void FinishProcessHandler(Process process, FinishProcessEventArgs e, EventPhases phase) { foreach (var itemInWorkflow in process.Subjects) { //publish } } 
-1
source

Source: https://habr.com/ru/post/912970/


All Articles