Tutorial: Customize workflow definitions
Sitefinity CMS workflow allows content to require reviewing by a privileged user before publishing. You may want to enforce more complex rules for determining the way an item must be approved. For example, you may want pages under a particular root to be approved by one set of approvers, while the rest of the pages to be approved by the default approvers. You can accomplish this by injecting your own code in the workflow definition to determine the approval workflow for content items.
This tutorial demonstrates how you can override the default workflow when a page is located under particular root pages. The custom workflow in this tutorial, applies the following logic:
- If the content is not a page » use the default workflow.
- If the content is a page under the top-level page Products » use a custom generated one-step workflow.
- If the content is a page under the top-level page Resources » use a custom generated two-step workflow.
- If the content is a page under the top-level page Documents » find in the database a workflow definition Workflow for Documents.
- Else » use the default workflow provided by the base class.
You can accomplish this scenario by descending from WorkflowDefinitionResolver and registering you new class with the ObjectFactory.
WorkflowDefinitionResolver class
This class has 2 overridable methods:
- IWorkflowExecutionDefinition ResolveWorkflowExecutionDefinition(IWorkflowResolutionContext)
This method returns a workflow that is used for approval of the item described by the IWorkflowResolutionContext. These are the most common implementations:
- Find an existing workflow definition in the database.
- Create your own definition using WorkflowDefinitionProxy class.
- For default behavior, call the method of the base class.
- IWorkflowExecutionDefinition GetWorkflowExecutionDefinition(Guid)
Given a GUID, this method returns workflow definition. If the GUID exists in the database, then you can call the base class's implementation. If you have created your own definition via code in ResolveWorkflowExecutionDefinition, then you must return that definition in this method.
Download Custom workflow definitions example
You can download the fully functional example from Sitefinity CMS GitHub custom-workflow-definition-resolver.