Drupal: Create Dynamical Menus with Menu Views

| Drupal Development | 23 seen

Today working on a customer's Drupal project, I found a kind of strange need - to display for authenticated users their flagged content in a drop-down menu - kinda Facebook, LinkedIn behavior, when you click on gear icon and magic happens - you see your latest messages, invitations, and e.t.c.

So I must admit - at the start I didn't have an idea - how actually to flag content. But luckily for me, a few years ago - I was playing with Flags Module and working on this project I decided flags will do exactly what we need - they are going to flag nodes.

First problems arise - we actually have two flags - Add to Favourite and Add to Complete. The problem arises - how to display both of these flags on a single views block and enable user to flag each of them.

The solution is quite  simple: add two Relationships on the same view:

Flags Relationships

Flags Relationships

Now - the flags is just a first stage of this task. Next task is to display flagged content in a nice drop-down menu.

My first idea was to create some views blocks and then to use CSS ul li to hide child item while parent item is not hovered (usual menu trick - which doesn't involve the use of any superfish or other menu modules), and display a drop-down menu (views block) when parent item is hovered.

The bad thing is - I didn't find a parents item :(

Few hours latter I found something great brought to us by LevelTen - Menu Views

About Menu views

Allows menu items to render views instead of links. This is useful for creating "mega-menus".

What Menu Views Does

Menu Views is a utility module. It provides back-end support for replacing a standard menu item link with a menu item view. Menu items (in any menu) now have the option of toggling between two different menu item types: link or view. Depending on which option is selected, the appropriate configuration form is displayed on the admin side and the appropriate type of item is rendered on the front-end.

What Menu Views Does NOT Do

Menu Views is NOT a theming/styling module for mega-menus. As stated above, this module is strictly a utility module for replacing menu item link with a view. Once the HTML markup is there, Menu View's job is done! Read#1794010: Menu Views is not working.

Depending on how a theme renders the primary and secondary navigation, this module may not work because the parent items may not ever be extended (regardless whether they are checked as such in the menu item). It is strongly recommended to use one of the following modules in your theme's menu region instead (see: Use menus in Drupal 7? You need Menu block module.).

Sponsorship

This module is sponsored and developed by LevelTen Interactive. LevelTen is a full-service interactive agency focused on building online brands by integrating digital strategy, Drupal development, and internet marketing.

Thank you LevelTen for this great module - you solved me a lot of time.

For now - I'm already seeing more places where menu views could be added.

Add new comment