Problem/Motivation

I noticed faulty behavior when using the Menu Block Export module (admin/config/user-interface/menu-block/export) to generate a MYMODULE_menu_block_blocks function for use in a custom module: All current 7.x versions generate export code that does not comply with the module's own API hook_menu_block_blocks (line 31 of menu_block.api.php).

This is generated by menu_block 7.x-2.5, 7.x-2.x and 7.x-3.x for a module named “custom” and random settings:

/**
 * Implements hook_menu_block_blocks().
 */
function custom_menu_block_blocks() {
  // The array key is the block delta used by menu block.
  return array(
    'custom-1' => array(
      'parent'      => main-menu:0,
      'title_link'  => 0,
      'admin_title' => 'whatever',
      'level'       => 2,
      'follow'      => '0',
      'depth'       => 2,
      'expanded'    => 1,
      'sort'        => 0,
    ),
  );
}

Using the code above in a custom module results in an error when I try to enable this module: parse error, expecting `')'' in custom.module

Proposed resolution

I compared the output to the API hook and it seems that the output should rather be:

function custom_menu_block_blocks() {
  // The array key is the block delta used by menu block.
  return array(
    'custom-1' => array(
      'menu_name'   => 'main-menu',
      'parent_mlid' => 0,
      'title_link'  => 0,
      'admin_title' => 'whatever',
      'level'       => 2,
      'follow'      => 0,
      'depth'       => 3,
      'expanded'    => 0,
      'sort'        => 0,
    ),
  );
}

Remaining tasks

Please review the attached patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, 0001-Refactor-menu_block-export-to-current-module-API.patch, failed testing.

tobias.grasse’s picture

Modified the patch to comply with PHP 5.3, which does not like the syntax

function_returning_array($parameter)[key-we-want]
tobias.grasse’s picture

Status: Needs work » Needs review
rossb89’s picture

Just ran into this, the export module does indeed currently export broken code (2.7 tested) and indeed not compatible with the hook_menu_blocks_block example in the API.

Just tested this patch, applied OK and solved the issue as far as I can see.

Surprised more people haven't ran into this!

rossb89’s picture

Status: Needs review » Reviewed & tested by the community

Marking as RTBC as the patch is relatively simple, has had no further implications that I have seen, and solves the completely broken export functionality.

JohnAlbin’s picture

Status: Reviewed & tested by the community » Needs work

I don't know how this got broken after I stopped actively maintaining it, but it definitely is broken now.

But your patch will break any block using "follow" feature. It needs to be a string. Please revert that.

Also, the config should be storing "parent", not the 2 separate "menu_name" and "parent_mlid". Please revert that too. You just need to add quotes around the parent value.

Christopher Riley’s picture

It would certainly be nice if this was cleaned up as I would love to be able to utilize the functionality but there is no way that it will work with the way it is. Any chance of getting this bumped to be a priority since it is advertised as a feature. If not it should be removed as its very misleading.

jmcintyre’s picture

Here's the patch, revised per John's recommendation in #6.

drupalmonkey’s picture

The quotes are definitely needed, it's not valid PHP without them.

This part though:

Also, the config should be storing "parent", not the 2 separate "menu_name" and "parent_mlid".

My exported blocks didn't work for me with them set as "parent". They just ended up as empty in their regions. With the settings as the separate "menu_name" and "parent_mlid" though, things worked. This was in 7.x-2.7.

tobias.grasse’s picture