You are here

function nice_menus_block in Nice Menus 5

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

Implementation of hook_block().

File

./nice_menus.module, line 123

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)';
      }
      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, '1'),
        '#options' => menu_parent_options(0, 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.
      $pid = variable_get('nice_menus_menu_' . $delta, '1');
      $direction = variable_get('nice_menus_type_' . $delta, 'right');
      if ($output = theme('nice_menu', $delta, $pid, $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 . '">' . $subject . '</span>';
      }
      else {
        $block['content'] = false;
      }
      return $block;
      break;
  }
}