We have been working on The Employee Experience Centre project which needed different publishing workflows for a content type used by various departments.
By default, Two modules -Workflow and Content Moderation- are available in Drupal Core which give you one workflow per content type.
In our case, We had another situation. Given the large size of the company, there are multiple departments. And the head of each department wanted to change the content publishing workflow. There would be content in a specific state of workflow. And suddenly, there would be a new directive to create a new workflow. But they wanted to keep following the earlier workflow for content which was already in process.
For this scenario, we had no option but to create a custom module.
- Default workflow module provides us the moderation state. We created specific state & transition based on the client requirement.
- Client agreed to define multiple workflows along with states. These were mostly fixed which could be utilized by different departments across the company. So, we created each one using custom code.
- Then we created a page to enable selection of workflow based on content type. On this page, we created a configuration form to list down all content types and departments.
- After selecting a department, we listed down all content types with existing workflows.
- Workflow can be changed for specific content. This permission was given to very specific roles only.
Routing for configuration form
Workflow configuration form
- Then in hook_node_presave or in hook_node_update, we can first check for existing workflow type for content type and department from configuration form. Then, we can set the value of moderation state in node.
// queryCheckExistingWorkflowTypeName service will fetch the workflow type by passing department_name and node type.
We managed to create this work around since project team agreed to have predefined workflow.
This story is not over yet. Actual requirement was to enable even admin users to create these workflows using configuration page. We are out of ideas on this. Would like to hear your suggestions.