You are here

function _submenutree_menutree_view in Submenu Tree 7.2

Same name and namespace in other branches
  1. 5 submenutree.module \_submenutree_menutree_view()
  2. 6 submenutree.module \_submenutree_menutree_view()
  3. 7 submenutree.module \_submenutree_menutree_view()

View the menu tree, either by poking into $node->content, or via the block functions

Parameters

$node: The node being operated upon. This is also used for configuration information.

$type: The type of menu to produce, either "submenutree" or "siblingmenutree"

$tree: A fragment of a menu tree to be viewed

1 call to _submenutree_menutree_view()
submenutree_node_view in ./submenutree.module
Implements hook_node_view().

File

./submenutree.module, line 537
Primarily Drupal hooks and processing the Submenu Tree display.

Code

function _submenutree_menutree_view($node, $type, $tree) {

  // Get configuration from $node, depending on $type
  $config_item = $type . '_title';
  $title = check_plain($node->{$config_item});
  $config_item = $type . '_display';
  $display = intval($node->{$config_item}) & SUBMENUTREE_DISPLAY_BLOCK_MASK;
  $display_in_block = intval($node->{$config_item}) & ~SUBMENUTREE_DISPLAY_BLOCK_MASK;
  $config_item = $type . '_view_mode';
  $view_mode = $node->{$config_item};
  $config_item = $type . '_links';
  $links = $node->{$config_item};

  // Generate the block title
  if ($display_in_block) {
    $block_title = $title;
    if ($block_title == '') {
      $block_title_type = variable_get('submenutree_block_title', 'current_title');
      switch ($block_title_type) {
        case 'leave_blank':
          $block_title = '';
          break;
        case 'content_title':
          $block_title = $node->title;
          break;
        case 'content_menu_direct_parent':
          $menu_trail = menu_get_active_trail($node->nid);

          // Select the title of the menu item directly above the current node
          $direct_parent = prev($menu_trail);
          if ($direct_parent) {
            $block_title = $direct_parent['title'];
          }
          break;
        case 'content_menu_parent':
          $menu_trail = menu_get_active_trail($node->nid);
          $level = variable_get('submenutree_block_title_content_menu_parent_level', 1);

          // Select the title of the menu item at the specified level above the current node
          if ($menu_trail[$level]) {
            $block_title = $menu_trail[$level]['title'];
          }
          break;
      }
    }

    // Wipe out $title so it doesn't get passed into the theme functions
    $title = NULL;
  }
  else {
    if ($title == '') {
      $title = NULL;
    }
  }
  $output = '';
  if ($display == SUBMENUTREE_DISPLAY_MENU) {
    $output = theme('submenu_tree_menu', array(
      'tree' => $tree,
      'title' => $title,
    ));
  }
  else {
    $items = array();
    foreach ($tree as $k => $v) {

      // Check that this is a node view
      if (empty($v['link']['hidden']) && strpos($v['link']['href'], 'node/') === 0) {
        $nid = drupal_substr($v['link']['href'], 5);
        $child = node_load($nid);
        $items[] = array(
          'node' => $child,
          'weight' => $v['link']['weight'],
          'title' => check_plain($v['link']['title']),
        );
      }
    }
    _submenutree_sort_items($items);

    // Now render our links or our nodes
    switch ($display) {
      case SUBMENUTREE_DISPLAY_TITLES:
        $output = theme('submenu_tree_titles', array(
          'items' => $items,
          'title' => $title,
        ));
        break;
      case SUBMENUTREE_DISPLAY_VIEW_MODE:
        $output = theme('submenu_tree_view_mode', array(
          'items' => $items,
          'title' => $title,
          'links' => $links,
          'view_mode' => $view_mode,
        ));
        break;
    }
  }
  if ($output) {
    if ($display_in_block == 0) {
      $node->content['submenutree'] = array(
        '#type' => 'container',
        '#attributes' => array(
          'class' => array(
            'submenutree',
          ),
        ),
        'tree' => array(
          '#markup' => $output,
        ),
      );
    }
    else {
      $blocks_map = array(
        'submenutree' => SUBMENUTREE_BLOCK_SUBMENU,
        'siblingmenutree' => SUBMENUTREE_BLOCK_SIBLINGMENU,
      );
      _submenutree_set_block_content($blocks_map[$type], array(
        'subject' => $block_title,
        'content' => $output,
      ));
    }
  }
}