I'm trying to embed a menu block into a panel. The menu block has the following relevant settings:

  • Starting level: 2nd Level (secondary)
  • Fixed parent item: Blogs - FYI, Blogs is a 1st level menu item.

When I view the page, the menu is blank. When I go back to configure the settings, Fixed parent item is reset back to <My Menu Name>.

This seems like a bug. Let me know what I can do to help fix it.

Comments

Lowkey’s picture

From what I can tell, the source of this error stems from failing to extract the menu link ID (mlid) from the parent_mlid in menu_tree_build() on line 254 in /path/to/drupal/sites/all/modules/menu_block/menu_block.module.

menu_tree_build() takes $config as parameter and expects it to look like this:

 * @param $config
 *   array An array of configuration options that specifies how to build the
 *   menu tree and its title.
 *   - delta: (string) The menu_block's block delta.
 *   - menu_name: (string) The machine name of the requested menu. Can also be
 *     set to MENU_TREE__CURRENT_PAGE_MENU to use the menu selected by the page.
 *   - parent_mlid: (int) The mlid of the item that should root the tree. Use 0
 *     to use the menu's root.
 *   - title_link: (boolean) Specifies if the title should be rendered as a link
 *     or a simple string.
 *   - admin_title: (string) An optional title to uniquely identify the block on
 *     the administer blocks page.
 *   - level: (int) The starting level of the tree.
 *   - follow: (string) Specifies if the starting level should follow the
 *     active menu item. Should be set to 0, 'active' or 'child'.
 *   - depth: (int) The maximum depth the tree should contain, relative to the
 *     starting level.
 *   - expanded: (boolean) Specifies if the entire tree be expanded or not.
 *   - sort: (boolean) Specifies if the tree should be sorted with the active
 *     trail at the top of the tree.

The $config['parent_mlid'] is expected to be an int, but is really a string that follows the pattern $menu_name:parent_mlid, for example main-menu:1128.

This becomes a problem when we get to line 325 in /path/to/drupal/sites/all/modules/menu_block/menu_block.module :

  // Prune the tree along the active trail to the specified level.
  if ($config['level'] > 1 || $config['parent_mlid']) {
    if ($config['parent_mlid']) {
      $parent_item = menu_link_load($config['parent_mlid']);
      menu_tree_prune_tree($tree, $config['level'], $parent_item);
    }
    else {
      menu_tree_prune_tree($tree, $config['level']);
    }
  }

The function menu_link_load(), found in /path/to/drupal/includes/menu.inc expects an integer :

/**
 * Get a menu link by its mlid, access checked and link translated for rendering.
 *
 * This function should never be called from within node_load() or any other
 * function used as a menu object load function since an infinite recursion may
 * occur.
 *
 * @param $mlid
 *   The mlid of the menu item.
 *
 * @return
 *   A menu link, with $item['access'] filled and link translated for
 *   rendering.
 */
function menu_link_load($mlid) {
  if (is_numeric($mlid)) {
    $query = db_select('menu_links', 'ml');
    $query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
    $query->fields('ml');
    // Weight should be taken from {menu_links}, not {menu_router}.
    $query->addField('ml', 'weight', 'link_weight');
    $query->fields('m');
    $query->condition('ml.mlid', $mlid);
    if ($item = $query->execute()->fetchAssoc()) {
      $item['weight'] = $item['link_weight'];
      _menu_link_translate($item);
      return $item;
    }
  }
  return FALSE;
}

A hotfix would be to replace line 328 in /path/to/drupal/sites/all/modules/menu_block/menu_block.module :

$parent_item = menu_link_load($config['parent_mlid']);

with these :

list($menu_name, $parent_mlid) = explode(":", $config['parent_mlid']);
$parent_item = menu_link_load($parent_mlid);

To have the set Fixed parent item show up, when you go back to configure the settings, line 429 in /path/to/drupal/sites/all/modules/menu_block/menu_block.admin.inc should be changed from

'#default_value' => $config['menu_name'] . ':' . $config['parent_mlid'],

to

'#default_value' => $config['parent_mlid'],

It probably takes a little more refactoring for the issue to be completely solved.
I'm using the module with Panopoly and I still need to figure out, how to set a fixed parent item that shows one level of children, while also showing the siblings of the parent.

caschbre’s picture

@Lowkey... I tried the hotfix you suggested but I'm still not able to

a) get Menu setting to retain a selected menu. It always reverts back to
.

b) get Fixed parent item to list anything other than
, let alone retain any setting.

Have you come across anything that resolves the issue?

JohnAlbin’s picture

Status: Active » Closed (cannot reproduce)

I'm trying to embed a menu block into a panel. The menu block has the following relevant settings:

Starting level: 2nd Level (secondary)
Fixed parent item: Blogs - FYI, Blogs is a 1st level menu item.
When I view the page, the menu is blank. When I go back to configure the settings, Fixed parent item is reset back to .

I can't reproduce.

webadpro’s picture

Issue summary: View changes

I'm actually facing the same problem. The parent item is never saved.

fredsted’s picture

Same here, webadpro. How come this issue is closed? Due to this I have to create a custom menu for each page. It's a nightmare to maintain.

Edit: This thread was referenced in the panopoly widgets module, didn't think it was the menu block module...I don't know if it's panopoly or this that is causing this