0

Using drupal 7, when creating new content of the type "Document" the current user roles must be added so I can later on show only Documents of his current role.

For example, we have the following user: this is Jake, he is a Firefighter. He creates a document about the dangers and pitfalls of being a firefighter. This is only relevant for Firefighters. So in the list of documents (view) I want Jake and all other Firefighters only to see Firefighter Documents.

So if Jake create new content of the type "document" I want to add his user roles and later on add a filter in the view so only Firefighters get to see Firefighter Documents

I want to have the following filter for the list Document view:

  • Published = true
  • Content type = Document
  • User role = current user roles (Firefighter in this case)

Access must be restricted for every user based on their role. For example, Jake the Firefighter is not allowed to view Policemen Documents

1

1 Answer 1

0

You don't have to add author's role to a node directly.
You can add user's role based Exposed Filter option in a view by using relationship. To do this please follow steps of below:

  1. Create your view as usual (like configure view name, display type etc)
  2. From Fields section add all desire fields.
  3. From Filter Criteria choose appropriate node type.
  4. Click on the Advanced button (indicated by an arrow on right side of the view).
  5. Click on the Add button of the Relationship section and add Content: Author as a relationship.
  6. Now Click on the Add button of the Filter Criteria section and add User: Roles as a filter. In this filter settings pop-up form, enable or check Expose this filter to visitors, to allow them to change it option then choose Is one of option as an operator.

Output/result:
enter image description here

2
  • A user is only allowed to show content of his own role. So for example, a Firefighter is only allowed to view Firefighter documents and a police officer is only allowed to view Police Documents. Therefore a Police officer can't view Firefighter Documents. I've edited my question for clarification. And the filter must be set on the current logged in user role, they're not allowed to choose
    – Ducky
    Jan 18, 2019 at 10:00
  • Then you can get more help from this question drupal.stackexchange.com/questions/98551
    – johirpro
    Jan 18, 2019 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.