0

I'm making a site using Drupal 8 and I have several roles defined, one of them is Writer. I made a view to show as a tab in the user profile pages called Backlist. If the user is a writer, they can add a list of their books they have written. Everyone visiting the site has access to the backlist information under that tab. What I'm trying to do is make it so the tab ONLY shows in profiles that are writers.

This is very similar to this question: Hide views tab display on user profile to profile owner That answer didn't work for me because it seems that the 'hide view' is no longer in the validation settings.

As I have it now, the tab shows all the time, and if there's no content, it just shows a message. So is it possible to hide a views tab, in a profile, based on the owner's role?

Contextual filters:

Configure contextual filter: User: User ID
validation criteria: User_ID
Restrict user based on role: Writer
Action to take if filter value does not validate: Display Contents of No results found
4
  • What is the Contextual filter configuration of your current Views? You can use the Validation in the Contextual filter to limit it to a user role.
    – prkos
    Nov 1, 2020 at 16:02
  • Configure contextual filter: User: User ID validation criteria: User_ID Restrict user based on role: Writer Action to take if filter value does not validate: Display Contents of No results found If there was something like "Hide View" in the actions that probably work, but it's not listed.
    – TomP
    Nov 1, 2020 at 17:16
  • The only way to hide the tab is to deny the access. I don't know if it's possible to do it in the Action to take if filter value does not validate
    – MacSim
    Nov 1, 2020 at 19:19
  • @MacSim I agree. An older version of Views had an option of Hide View as one of the actions, but that isn't there anymore. I'm not even sure if a custom module could do this.
    – TomP
    Nov 1, 2020 at 19:31

1 Answer 1

1

Just under Display content of "No results found" I see Display "Access denied" you need to use that one.

Denied users won't see the tab anymore.

If the display of your view is a page you can even manage the access directly into the "page's parameters" block and restrict the access by user role without using a contextual filter (unless the view really needs one).

3
  • I tried that but the tab still shows and the page shows my access denied message
    – TomP
    Nov 2, 2020 at 18:56
  • Did you tried both options ? I mean did you tried using the page's parameters restrictions too ?
    – MacSim
    Nov 2, 2020 at 20:14
  • I might be missing something so bear with me. I want it so if there is listings there, because the viewed profile is a Writer, everyone can see that info. If the user profile isn't a Writer, I don't want the tab to show at all. The end game is to have tabs that only show if the profile being viewed belongs to a Writer. I know, confusing, right?
    – TomP
    Nov 5, 2020 at 14:00

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.