Hi all.. This post is about how to develop a workflow scenario without using workflow module in Drupal 7. I have been searching online on how to develop a workflow case for a project, and mostly what I get is a recommendation of different types of module like ‘workflow’, ‘workbench’, etc. All these also includes fine knowledge about events and triggers module which seemed to be a bit complicated to me.
So rather I tried the following way to develop the workflow just using ‘rules’ and custom field of my content type. In general what I did is, I created a custom select list field for my content type with the values like draft, needs review and published. Then I used the rules to change and also to check the state of these fields at times when needed. A detail description is as below:
I created a Content type ‘story’ with a select field ‘workflow’. The values of the workflow are ‘draft, needs review, reviewed, needs work, published’.
The very first rule I needed to set is ‘unpublish on publish’. This is to make sure that stories created by users are not published automatically. This rule was for the event ‘After saving new content of type Story’. The conditions I set was data comparison that [node:author:roles] was not equal ‘editor’, ‘publisher’, ‘manager’ or ‘administrator’. FYI, I used ‘roles’ module to develop these roles.
In the action section I selected ‘unpublish content’ and ‘set a data value’ of [node:field-workflow] to ‘needs review’. Thats it. This is to ensure that the node is never published and my workflow value changes to ‘needs review’ from ‘draft’. The final image of this rule is given below:
Then I created another rule with the same conditions and actions for the event: ‘After updating existing content of type Story’, to make sure that whenever a user make changes the node is unpublished and workflow is set to ‘needs review’.
The third rule I created was ‘publish article’ which only worked before a node is saved or after updating an existing content. This rule checked if the user roles are administrator and workflow value is ‘needs review’ then it published the content and changed the value of workflow to ‘published’.
To elaborate the scenario:
I created this rule on two different events: ‘Before saving content’ and ‘After updating existing content’.
Then I checked the following conditions:
- Content is of type: story
- User has role(s): User: [site:current-user], Roles: publisher, manager, editor, administrator
- Data Comparison: if [node:field-workflow] is set to ‘needs review’
Then in Actions I published the node and set the data value of workflow to published. That’s it. Quite simple.
That’s the way I did it and it seems logical to me. If you have any suggestions or questions feel free.
Thank you
Nice article, It was helpful