28 January, 2022 seen 664This is an article back from 2014, when I had the vision to launch a web agency in Tbilisi, Georgia. In the end, I didn…
Working on a customers project, we faced a need to have many different Drupal user roles to have on site. I will speak about two of them today - Journalist and Editor.
As you might understand already we are talking about a media portal, where there is a need to have a separate user account with different roles and permissions.
Here comes a basic scenario we need to achieve - a journalist creates an article, saves it, but article is not going to be published, it will be directed to another Drupal user with role editor, to review that article and only then to publish that article.
To achieve following behaviour the only way I can see we can do this is by using Drupal Rules module, let me explain, why we cannot use default user permissions.
You can read my tutorial working with Drupal roles and permissions here
First of all - I believe this should be in Drupal core, but it's not for Drupal 7 version, when creating new roles, whe can limit some roles to create, edit or delete some content, unfortunately we cannot limit can user roles created content are published or unpublished, by default all content will be published if user has permission to create any piece of content.
Drupal User Roles and Permissions
On the other hand, we are left with another option, we are making all content unpublished on Content type settings page.
Editing Drupal Content Type settings
In such scenario all nodes created by any user role (depending on their permissions) would be saved and not published. Which I believe is not the worst option, if we are not looking to involve other modules, for example Drupal Rules.
In our case, after journalist would create and save new articles, they all would be unpublished, and editor would need to manually change publishing settings for each node, after revising content. As I said, not the worst scenario.
How to do it with Drupal rules
At first you will need to install Drupal Rules module, you can do it with drush or old fashioned way with ftp program.
Once your Drupal rules module is installed and enabled go to admin/config/workflow/rules:
Drupal Rules Admin page
Now lets build our first rule for journalists:
Creating Drupal Rule
- Give a name for your rule - Journalist Unpublished Node
- React on event - from a drop down menu choose - After saving new content
- You can restrict by type - from drop down menu choose your content type
After saving your new rule you must add conditions and actions for it
Drupal rules Conditions and Actions
- Condition - > User has role (s) Journalist
- Actions - > Unpublish content
Now save your Rules reactions, log in to your Drupal site with journalist role and test if everything went smoothly.
Creating Drupal rule for Editor (publish node after saving content)
The process here is the same, with just one difference in this case we are going react on event after updating existing content and we will set that nodes to be published:
Drupal Rules updating existing content
Let me know if that helped for you - If not, drop me a comment - i will try to help you out with your Drupal rules configuration.
About Drupal Rules
The Rules module allows site administrators to define conditionally executed actions based on occurring events (known as reactive or ECA rules). I
Example use cases
- Build flexible content publishing workflows changes
- Send customized mails to notify your users about important
- Create custom redirections, system messages, breadcrumbs, ...
- Build an eCommerce store using Drupal Commerce
And many more...
- Obviously, you may use reaction rules to react upon any event with custom conditions and actions.
- Allows functionality to be re-used via components (Drupal 6: Rule sets only).
- Flexible scheduling system that allows scheduling any component / action.
- Users can share their customizations by using the built-in import/export feature. For that the module also integrates with Features.
- Modular input evaluation system - for example you can install the Token module and use it in every action.
- The module has been developed with site performance in mind, so it makes use of caching routines to speed up rule evaluation.
- Rules 2.x (Drupal 7 only) features improved APIs, a new admin UI, support for all entity types, parameter configuration via simple data selection (i.e. just pass
node:authoras argument) and much more. See this blog post for more details.