Provides a Views filter that filters nodes by whether they are referenced in a specific menu.
This module adds a Views filter called "In menu" to node-based Views. It lets you restrict results to nodes that have a menu link in a chosen menu, matching either direct node links or links that point to the node via a path alias.
- Drupal core: 10.x or 11.x
- Core modules:
views
,menu_link_content
,path
- Enable the module like any other Drupal module.
- UI: Extend → search for "Node in Menu" and enable it.
- Drush:
drush en node_in_menu -y
- Create or edit a View of type Content.
- In the View, under Filter criteria, click Add and search for In menu.
- Add the filter and select the target Menu from the dropdown.
- Save the View. The results will now only include nodes that have an enabled menu link in the selected menu.
- Registers a Views filter plugin
@ViewsFilter("node_in_menu")
and exposes it on thenode_field_data
base table. - The filter adds an
EXISTS
subquery againstmenu_link_content_data
, also checkingpath_alias
so links via aliases are matched.
- Works on node-based Views (base table
node
/node_field_data
). - Expects the core
menu_link_content
andpath
modules to be enabled.
- Only checks for enabled menu links in the chosen menu.
- Does not currently support filtering by multiple menus at once.
- Code is PSR-4 under
src/
and the Views integration lives innode_in_menu.views.inc
. - Run
drush cr
after enabling or making code changes to rebuild caches.
GPL-2.0-or-later. See LICENSE.txt
.