We had a case where we wanted to treat all mega menus the same, but vary the content in them based on various fields/etc on the node the menu item linked to. We could have created a separate mini panel for each menu item; however, it seemed more elegant to have menu_minipanels pass the node into the mini panel as a context since we can readily detect links to nodes and can easily isolate the corresponding node ID.

Now, I'm not sure if this is the "right" or best way to do this... but here is a proof-of-concept patch for menu_minipanels. Here's how it works:

  1. When preparing to add the mini panels in menu_minipanels_page_alter(), menu_minipanels now retrieves the link_path for each menu link that has a mini panel (single query retrieves them all)
  2. For those menu links that link to node/*, it passes the node ID via a new parameter to _menu_minipanels_render_panel()
  3. After the minipanel is loaded, _menu_minipanels_render_panel() loads the passed node ID into any required node context on the mini panel.

This lets you use a node context in the minipanel content based on the node to which the menu item links.

In theory, an alternate (probably better?) approach is to present a required context form in the menu link settings. However, until that's implemented, this is an alternative that adds one query per page load and doesn't otherwise interfere with existing functionality.

CommentFileSizeAuthor
menu_minipanels-node_context.patch2.47 KBJosh Benner

Comments

damienmckenna’s picture

Status: Needs review » Closed (won't fix)

Thanks, but I'm not comfortable hardcoding the system to work like this. At the very least it should be made generic to work on entities rather than only work on nodes.