What is an action handler?
An action handler is a piece of code (a proper class) that gives you the possibility to react on the actions performed by any user in the content tree. For example, you can perform some actions in each node in the tree content is published. An example will explain in detail:
For a concrete example, I took the position that umbraco has the build in mechanism to define the values of properties Devault new content. The new action will Handler Devault write values to properties of a document type defined.
How to implement an action handler
You can implement your own action in any Handler. NET as a class. In this example, I'll do a class project own library to show how the complete cycle.
1. So in VS.NET create a class library project. Give it a name of your choice. In this example, the name of the project is TH.Umb.Sandbox.Library.
2. Add a new class and give it a name of your choice. In this example, the name of the class is DefaultValueHandler
3. Add references businesslogic.dll, and cms.dll interfaces.dll from the bin folder umbraco.
4. Let class implements the interface umbraco.BusinessLogic.Actions.IActionHandler.
5. Implement HandlerName the function that returns the name of this action handler.
6. Implement returnAction the function that defines the actions to which the action handler will react.
7. Last but not least the implementation of the Run function that does the job. Here you can set this code should be executed on this measure.
Thus, at least, you should have a code like this:
An action handler is a piece of code (a proper class) that gives you the possibility to react on the actions performed by any user in the content tree. For example, you can perform some actions in each node in the tree content is published. An example will explain in detail:
For a concrete example, I took the position that umbraco has the build in mechanism to define the values of properties Devault new content. The new action will Handler Devault write values to properties of a document type defined.
How to implement an action handler
You can implement your own action in any Handler. NET as a class. In this example, I'll do a class project own library to show how the complete cycle.
1. So in VS.NET create a class library project. Give it a name of your choice. In this example, the name of the project is TH.Umb.Sandbox.Library.
2. Add a new class and give it a name of your choice. In this example, the name of the class is DefaultValueHandler
3. Add references businesslogic.dll, and cms.dll interfaces.dll from the bin folder umbraco.
4. Let class implements the interface umbraco.BusinessLogic.Actions.IActionHandler.
5. Implement HandlerName the function that returns the name of this action handler.
6. Implement returnAction the function that defines the actions to which the action handler will react.
7. Last but not least the implementation of the Run function that does the job. Here you can set this code should be executed on this measure.
Thus, at least, you should have a code like this:
using System;
namespace TH.Umb.Sandbox.Library
{
public class DefaultValueHandler : umbraco.BusinessLogic.Actions.IActionHandler
{
string umbraco.BusinessLogic.Actions.IActionHandler.HandlerName()
{
return "TH.Umb.Sandbox.Library.DefaultValueHandler";
}
umbraco.interfaces.IAction[] umbraco.BusinessLogic.Actions.IActionHandler.ReturnActions()
{
return new umbraco.interfaces.IAction[] { new umbraco.BusinessLogic.Actions.ActionNew() };
}
Boolean umbraco.BusinessLogic.Actions.IActionHandler.Execute(
umbraco.cms.businesslogic.web.Document documentObject,umbraco.interfaces.IAction action)
{
if (documentObject.ContentType.Alias == "th_sandbox_defaultvaluetest")
{
try
{
umbraco.cms.businesslogic.property.Property p =
documentObject.getProperty("DefaultValueProperty");
if (p == null) { return false; }
p.Value = "This is the default value set by an action handler";
documentObject.Save();
}
catch (Exception)
{
return false;
}
return true;
}
else
{
return false;
}
}
}
}
A word from the function of returnAction: The return variable is an array of actions. Thus, you can come back to action. Therefore, you can manage more than one type of action with an action Handler.
A word to the execution of the function: The first item you get from this function is called documentObject and it is the document upon which this action is the stage. The second parameter is the action that is the stage. So if you defined an action returnAction you can delay the action you handle at this time.
How to install the action handler
The installation is done by copying the dll in the bin folder umbraco:
1. First build the project release (right click on the project, select new build).
2. Then go to the project file to select the DLL from the bin / output folder (in this case, select the TH.Umb.Sandbox.Library.dll) and copy it into the bin folder umbraco.
That's it. Now the manager is installed and will perform all the actions you have selected.
Supported Actions
•Assign Domain
•Audit
•Copy
•Delete
•Disable
•Empty Transcan (new in v3)
•Export
•Import
•Move
•New
•Notify
•Package
•PackageCreate
•Protect
•Publish
•Quit
•Refresh
•RePublish
•Rights
•Rollback
•Save
•SendToTranslate (new in v3)
•Sort
•ToPublish
•Translate (new in v3)
•UnPublish
•Update
0 comments:
Post a Comment