You are here

function nice_menus_block in Nice Menus 6

Same name and namespace in other branches
  1. 5 nice_menus.module \nice_menus_block()
  2. 6.2 nice_menus.module \nice_menus_block()

Implementation of hook_block().

File

./nice_menus.module, line 83
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;
      break;
    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('Source Menu Tree'),
        '#description' => t('The menu tree 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_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;
      break;
    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_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');
      if ($output = theme('nice_menu', $delta, $menu_name, $mlid, $direction)) {
        $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;
      break;
  }
}