Facilitator: Douglas Robar
Present: Thomas H, and many others.
Niels had said, "action handlers are the most powerful feature in umbraco; they will change your life." I wanted someone to show me when and how to use them. It is actually very simple!
When you want to add automated behaviors to umbraco that aren't built-in, an action handler is the way to do it.
Example uses:
- Add to the lucene index on publish
- Add more workflow items
- Create nodes for blog nodes (year, month, day)
- Custom logging
Action handlers are only available for content nodes (media and the other sections have been requested and we hope they'll appear in a future version). Action handlers can be triggered on a variety of events, such as publish, unpublish, assign domain, export, import, move, create, notify, publish, save, quit, refresh, sort, send to translate, etc.
An example can be found in the TH.FollowUrl package, which can be downloaded from http://www.thoehler.com/en/projects/followurl.aspx. This action handler is triggered on publishing to set update the NiceUrl by writing information in a table. An associated not found handler then looks in that table for other nodes that might be appropriate.
There is also a good umbraco book at http://www.umbraco.org/documentation/books/creating-and-using-an-action-handler
Creating an action handler is very easy. First, open Visual Studio and create a new Windows Class Library project. Add any references to the umbraco business logic, cms, etc. as necessary to your handler. Then, implement the umbraco.businesslogic.actiona.iactionhandler interface, which has three methods and one property:
- Handlername property – the name of your handler, as a string.
- Execute method – specify which node to work against, which action to be triggered on. Return true or false to denote the success or failure of your handlers.
- Action type method –
- Returnactions - Define which action this handler is working against.
One action handler can be triggered by multiple actions, such as publish, save, unpublish, etc. This might not follow the best coding practice guidelines, however.
Then, copy the dll to the /bin folder and it is automatically installed and ready to run.
Beware that you do not create an infinite loop in your action handler; always check to see if the value has changed before running your action handler.
The Not Found handler is similar, but is not an action handler. There is an umbraco book on Not Found Handlers at http://www.umbraco.org/documentation/books/not-found-handlers.
Feature Request: It would be nice to have an optional config file to disable a handler or specify which order to run if there are multiple action handlers for the same action.