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.
Comment | File | Size | Author |
---|---|---|---|
#8 | Correct_export_PHP_error-2482683-0008.patch | 543 bytes | jmcintyre |
Comments
Comment #2
tobias.grasse CreditAttribution: tobias.grasse commentedModified the patch to comply with PHP 5.3, which does not like the syntax
Comment #3
tobias.grasse CreditAttribution: tobias.grasse commentedComment #4
rossb89 CreditAttribution: rossb89 at ComputerMinds commentedJust 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!
Comment #5
rossb89 CreditAttribution: rossb89 at ComputerMinds commentedMarking as RTBC as the patch is relatively simple, has had no further implications that I have seen, and solves the completely broken export functionality.
Comment #6
JohnAlbinI 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.
Comment #7
Christopher Riley CreditAttribution: Christopher Riley commentedIt 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.
Comment #8
jmcintyre CreditAttribution: jmcintyre as a volunteer commentedHere's the patch, revised per John's recommendation in #6.
Comment #9
drupalmonkey CreditAttribution: drupalmonkey as a volunteer commentedThe quotes are definitely needed, it's not valid PHP without them.
This part though:
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.
Comment #10
tobias.grasse CreditAttribution: tobias.grasse commented