Abstract:

Drupal views should provide flexible functionality for listing different types of entities data and connecting all their relations. The menu system currently seems to be hardly separated from this functionality ("something very different" ;)).
This seems strange and leads to flexibility problems when solving (quite common) tasks like listing up all child nodes of the current node (node hierarchy). This is for example typically the case on overview pages in the menu tree (which shell show the same children hierarchy as the menu itself).

So I'd suggest to add better menu relations for Drupal 8 views like modules like https://www.drupal.org/project/menu_node and https://www.drupal.org/project/menu_node_views did before using workarounds.
The reason why I see this in core is, that both components (and especially the menu) is part of core and from my point of view this is a missing connection / functionality between menu and views.

Problem:

There is no proper D8 views integration for menu and node (or perhaps even other entities) to use these relations in views.

Context:

Building views which show the subpages of the currents node menu entry for example is only possible writing special custom code or module. Views is not really helpful here and if it is, then it's not user friendly.

Proposed solution:

Extend the menu_link_content (and perhaps node) modules for a better menu_link views relationship integration to provide (contextual) filters for menu_link item parents, menu item id's, menu item referenced nodes, etc.

The views integrations should provide similar functionality of what Taxonomy Terms already provide, as much as possible, for example

  • Parent / Child & Depth handling (also allow relating items assigned to children menu items)
  • Expose all menu item properties e.g. allow to sort by weight
  • ...

References:

Drupal 7 solutions / "workarounds" (if I may call it so because of the additional tables tracking the relationships).
https://www.drupal.org/project/menu_node
https://www.drupal.org/project/menu_node_views

Drupal 8+:
https://www.drupal.org/project/menu_entity_index
https://www.drupal.org/project/views_menu_children_filter

Thank you all very very much for your great D8 work!

It would be really really nice to discuss an integration like this. I think Drupal is lacking this since D6.

Comments

Anybody created an issue. See original summary.

Anybody’s picture

Issue summary: View changes
bmcclure’s picture

This is an extremely common requirement on our sites. We often end up needing to use methods which don't feel "right," when it seems like showing a node's menu children in a view should be functionality available without jumping through any hoops.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

awasson’s picture

Yes, I'd agree this is a fairly common feature in the sites I build. I often have main index page views that display teaser information for staff members or company officers, products, etc... that I build in a view. Each views-row contains a link to the node.

If the node, menu-item weight was available within the view, we could sort the view by menu weight.

It seems like a pretty simple concept.

contiveros’s picture

This. This right here. Beating myself over my head right now trying to get menu items in views.

John Pitcairn’s picture

Take a look at the menu_entity_index module.

Anybody’s picture

Thank you very much for the hint! That's at least a very good starting point.

bmcclure’s picture

That module looks pretty great! I was unaware of it until now.

I maintain the D8 version of a module with a similar (but simpler) goal: https://www.drupal.org/project/views_menu_children_filter

The primary difference being Views Menu Children Filter is solely for Views filtering, and it doesn't add additional indexes.

Now that I know menu_entity_index exists, I'm curious to try it on a project--it looks like perhaps a better all-around solution.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

AaronMcHale’s picture

I'd be keen for this to move forward, @bmcclure would you be interested in writing a patch that addresses this based on the code in your views_menu_children_filter module? Alternatively I might have some time in the future to write a patch but I'm not sure at this point if I will.

Thanks

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anybody’s picture

I agree with #12 that @bmcclure's module might be a good step for core integration.
menu_entity_index on the other hand uses duplication and an own index which isn't a good way for core I think. This should be solved on the existing data structures.

Views definitely needs support for menu item relationships.

Anybody’s picture

andypost’s picture

Status: Active » Closed (duplicate)
Related issues: +#2777749: Add menu_link_content support into views

Surely it is duplicate of #2777749: Add menu_link_content support into views
And the pointed issue already has some patches to review

Anybody’s picture

Issue summary: View changes
Anybody’s picture

Issue summary: View changes