function nice_menus_block in Nice Menus 6.2
Same name and namespace in other branches
- 5 nice_menus.module \nice_menus_block()
- 6 nice_menus.module \nice_menus_block()
Implements hook_block().
File
- ./
nice_menus.module, line 122 - Module to enable CSS dropdown and flyout menus.
Code
function nice_menus_block($op = 'list', $delta = 0, $edit = array()) {
global $user;
switch ($op) {
case 'list':
for ($i = 1; $i <= variable_get('nice_menus_number', '2'); $i++) {
$blocks[$i]['info'] = variable_get('nice_menus_name_' . $i, 'Nice menu ' . $i) . ' (Nice menu)';
// We have too many things changing per user, per page to cache.
$blocks[$i]['cache'] = BLOCK_NO_CACHE;
}
return $blocks;
case 'configure':
$form['nice_menus_name_' . $delta] = array(
'#type' => 'textfield',
'#title' => t('Menu Name'),
'#default_value' => variable_get('nice_menus_name_' . $delta, 'Nice menu ' . $delta),
);
$form['nice_menus_menu_' . $delta] = array(
'#type' => 'select',
'#title' => t('Menu Parent'),
'#description' => t('The menu parent from which to show a Nice menu.'),
'#default_value' => variable_get('nice_menus_menu_' . $delta, 'navigation:0'),
'#options' => menu_parent_options(menu_get_menus(), 0),
);
$form['nice_menus_depth_' . $delta] = array(
'#type' => 'select',
'#title' => t('Menu Depth'),
'#description' => t('The depth of the menu, i.e. the number of child levels starting with the parent selected above. Leave set to -1 to display all children and use 0 to display no children.'),
'#default_value' => variable_get('nice_menus_depth_' . $delta, -1),
'#options' => drupal_map_assoc(range(-1, 5)),
);
$form['nice_menus_type_' . $delta] = array(
'#type' => 'select',
'#title' => t('Menu Style'),
'#description' => t('right: menu items are listed on top of each other and expand to the right') . '<br />' . t('left: menu items are listed on top of each other and expand to the left') . '<br />' . t('down: menu items are listed side by side and expand down'),
'#default_value' => variable_get('nice_menus_type_' . $delta, 'right'),
'#options' => drupal_map_assoc(array(
'right',
'left',
'down',
)),
);
return $form;
case 'save':
variable_set('nice_menus_name_' . $delta, $edit['nice_menus_name_' . $delta]);
variable_set('nice_menus_menu_' . $delta, $edit['nice_menus_menu_' . $delta]);
variable_set('nice_menus_depth_' . $delta, $edit['nice_menus_depth_' . $delta]);
variable_set('nice_menus_type_' . $delta, $edit['nice_menus_type_' . $delta]);
break;
case 'view':
// Build the Nice menu for the block.
list($menu_name, $mlid) = explode(':', variable_get('nice_menus_menu_' . $delta, 'navigation:0'));
$direction = variable_get('nice_menus_type_' . $delta, 'right');
$depth = variable_get('nice_menus_depth_' . $delta, '-1');
if ($output = theme('nice_menus', $delta, $menu_name, $mlid, $direction, $depth)) {
$block['content'] = $output['content'];
if (variable_get('nice_menus_type_' . $delta, 'right') == 'down') {
$class = 'nice-menu-hide-title';
}
else {
$class = 'nice-menu-show-title';
}
// If we're building the navigation block
// use the same block title logic as menu module.
if ($output['subject'] == t('Navigation') && $user->uid) {
$subject = $user->name;
}
else {
$subject = $output['subject'];
}
$block['subject'] = '<span class="' . $class . '">' . check_plain($subject) . '</span>';
}
else {
$block['content'] = FALSE;
}
return $block;
}
}