Score:0

How do I hide the tab menu link when a view is empty?

gu flag

I have a view with a menu tab link and an attachment, which displays rows of other nodes, depending on the contextual filter.

This view has a custom path(/node/%node/view-custom-path).

How do I show the menu link only when the following conditions are met?

  • The node has some taxonomy terms
  • The view attachment is empty

I have already set the needed term as filter criteria, but the link ignores it and it's shown everywhere. I can display an empty message and send 404 headers when the view is empty, but how can I hide the link as well?

I tried using basic validation in contextual filters and setting Hide view or Show page not found, but that didn't help.

Alfred Armstrong avatar
cn flag
Have you tried implementing a custom access callback for the route? That's where I'd usually attempt to solve this type of problem.
Score:0
de flag

First, get the route name of the view. Then, alter that route, giving it a custom access callback that checks required conditions. Deny access if they are not met. Tabs are only shown if/when the user has access to the route.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.