function menu_attach_block_preprocess_links in Menu Attach Block 7
Implements hook_preprocess_HOOK().
File
- ./
menu_attach_block.module, line 206 - Module to enable adding a block to menu item.
Code
function menu_attach_block_preprocess_links(&$variables) {
$attached_block = FALSE;
// Very quick hacky check to prevent notices on install.
// @todo Investigate in more detail.
if (array_key_exists('links', $variables) && is_array($variables['links']) && count($variables['links'])) {
foreach ($variables['links'] as $key => &$link) {
if (is_array($link) && array_key_exists('menu_attach_block', $link) && empty($link['menu_attach_block']['name']) == FALSE) {
$attached_block = TRUE;
$link['attributes']['class'][] = 'attached-block';
// Rebuild the keys of the array, preserving the order. Array keys are
// used for keys in the li element of link lists - @see theme_links.
$new_links[$key . ' attached-block'] = $link;
}
else {
$new_links[$key] = $link;
}
}
if ($attached_block) {
$variables['links'] = $new_links;
}
}
}