You are here

function better_jump_menu_block_view in Better Jump Menu 7

Implements hook_block_view().

File

./better_jump_menu.module, line 105

Code

function better_jump_menu_block_view($delta = '') {
  switch ($delta) {
    case 'localtasks':
      $subject = t('Local tasks');
      break;
    case 'booknavigation':
      $subject = t('Book navigation');
      break;
    default:
      $menus = menu_get_menus(TRUE);
      $subject = isset($menus[$delta]) ? $menus[$delta] : $delta;
      break;
  }
  $configuration = _better_jump_menu_get_block_default_configuration($delta);
  $configuration = $configuration + array(
    'delta' => $delta,
  );
  if ($delta == 'localtasks') {

    // Collect the local tasks.
    // This bit of code is taken from the jump menu module.
    // See: https://www.drupal.org/project/jump_menu
    $links = menu_local_tasks(0);
    $links_secondary = menu_local_tasks(1);
    $secondary = count($links_secondary['tabs']['output']) != 0 ? TRUE : FALSE;
    if ($links['tabs']['count'] > 0) {
      $options = array();
      foreach ($links['tabs']['output'] as $l) {
        if ($l['#link']['access'] == TRUE) {
          $url = url($l['#link']['href'], array(
            'absolute' => TRUE,
          ));
          $index = uniqid() . '::' . $url;
          $options[$index] = t($l['#link']['title']);
          if ($secondary && $links_secondary['tabs']['output'][0]['#link']['tab_parent_href'] == $l['#link']['href']) {
            foreach ($links_secondary['tabs']['output'] as $sl) {
              $url = url($sl['#link']['href'], array(
                'absolute' => TRUE,
              ));
              $index = uniqid() . '::' . $url;
              $options[$index] = '- ' . t($sl['#link']['title']);
            }
          }
        }
      }
      return array(
        'subject' => $subject,
        'content' => drupal_get_form('better_jump_menu', $options, $configuration),
      );
    }
  }
  if ($delta == 'booknavigation') {
    $options = array();
    $menu_machine_name = NULL;
    if ($node = menu_get_object('node')) {
      if (isset($node->book) && ($bid = $node->book['bid'])) {
        $menu_machine_name = book_menu_name($bid);
      }
    }
    if (is_null($menu_machine_name)) {
      return array();
    }

    // Get the data from the menu.
    $build = menu_tree_output(menu_tree_all_data($menu_machine_name));
    if ($build) {

      // Convert to an array of option elements.
      _better_jump_menu_convert_to_options_array($build, $options, $configuration);
      return array(
        'subject' => $subject,
        'content' => drupal_get_form('better_jump_menu', $options, $configuration),
      );
    }
  }
  if ($delta) {
    $options = array();

    // Get the data from the menu.
    $build = menu_tree_output(menu_tree_all_data($delta));
    if ($build) {

      // Convert to an array of option elements.
      _better_jump_menu_convert_to_options_array($build, $options, $configuration);
      return array(
        'subject' => $subject,
        'content' => drupal_get_form('better_jump_menu', $options, $configuration),
      );
    }
  }
}