2

I have a pretty particular issue that I'm running into with setting up an Administration View using Contextual Filters.

I've set up a view to handle /admin/content.

Basically, what I would like is for users in a particular role to see the content that they are authors of, and one specific other content type, for which nodes are submitted by anonymous users through a webform.

So, to recap, users in this role need to see:

  • Nodes that they are the author of
  • Nodes submitted by anonymous users, of a specific content type

Any thoughts?

1 Answer 1

1

You shouldn't need contextual filters for this as nothing needs to be passed in via the URL.

It should work like this using regular filters:

  1. Create a node view
  2. Add a relationship for "Content: Author"
  3. Add a filter for "Content: Type" and restrict to the specific content type you refer to.
  4. Add a filter for "User: Current" and set it to "Yes". This will be using the relationship you defined in step 2.
  5. Click the drop down next to the filter criteria heading and click "And/Or, Rearrange".
  6. Change the operator for your 2 filters to "Or". Then you will see on the right it says current user or content type. Then click apply. - Note that if you have other filters set you may have to click the "Create new filter group" button then add these 2 filters to the new group then use "Or" within that group and "And" for the rest.
5
  • Nice answer, typical @rooby style. Think this could serve as an advanced example of what you can do with Views, and how many possible options there are throughout the Views UI. I'm just curious if you can also think of a real world sample for which the specs in this question would be the question to be solved ... Commented Aug 7, 2015 at 5:40
  • I'm accepting your answer because it does exactly what the question asks, thank you! Now that I've tried it I realize I have a slightly different problem as well- is it possible to then use this same view for "generic editors" who need to see everything, if those users have a different role? Or do I have to create and use separate views for these. This is an existing site so using the same view would be ideal.
    – paintedsky
    Commented Aug 7, 2015 at 23:26
  • I can't think of an easy way to make that work without writing PHP code. drupal.stackexchange.com/a/98617/10729 gives a solution to that using a PHP filter. Personally I wouldn't do it that way because I don't put PHP code in the database, but if you're okay with that you should be able to get it to work. If it was me I would have 2 separate pages for "Administer content" and "My content" or similar since the pages do have different use cases. For more info on PHP in the database see drupal.stackexchange.com/q/2509/10729 and drupal.stackexchange.com/q/70297/10729
    – rooby
    Commented Aug 8, 2015 at 4:38
  • @Pierre.Vriens I'm not sure I understand your question.
    – rooby
    Commented Aug 8, 2015 at 4:43
  • @rooby image you use this when teaching a class, which situation in the real world would you refer to to introduce this question? Like which real role(s), which content type, etc? Commented Aug 8, 2015 at 5:15

Your Answer

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

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