You are here

function _submenutree_menutree_view in Submenu Tree 6

Same name and namespace in other branches
  1. 5 submenutree.module \_submenutree_menutree_view()
  2. 7.2 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_nodeapi_view in ./submenutree.module

File

./submenutree.module, line 336

Code

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

  // grab config 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 . '_weight';
  $weight = $node->{$config_item};

  // tweak $title
  if ($display_in_block) {
    $block_title = $title;
    if ($block_title == '') {
      $block_title = $node->title;
    }

    // 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', $tree, $title);
  }
  else {
    $items = array();
    foreach ($tree as $k => $v) {

      // Check that this is a node view
      if ($v['link']['hidden'] == false && strpos($v['link']['href'], 'node/') === 0) {
        $nid = substr($v['link']['href'], 5);
        $child = node_load(array(
          'nid' => $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
    $links = false;
    switch ($display) {
      case SUBMENUTREE_DISPLAY_TITLES:
        $output = theme('submenu_tree_titles', $items, $title);
        break;
      case SUBMENUTREE_DISPLAY_TEASERS_LINKS:
        $links = true;
      case SUBMENUTREE_DISPLAY_TEASERS:
        $output = theme('submenu_tree_teasers', $items, $title, $links);
        break;
      case SUBMENUTREE_DISPLAY_FULLTEXT_LINKS:
        $links = true;
      case SUBMENUTREE_DISPLAY_FULLTEXT:
        $output = theme('submenu_tree_fulltext', $items, $title, $links);
        break;
    }
  }
  if ($output) {
    if ($display_in_block == 0) {
      $node->content[$type] = array(
        '#value' => $output,
        '#weight' => $weight,
      );
    }
    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,
      ));
    }
  }
}