You are here

function _taxonomy_menu_item in Taxonomy menu 7

Same name and namespace in other branches
  1. 6.2 taxonomy_menu.module \_taxonomy_menu_item()

Helper function: Inserts and updates menu along with taxonomy changes.

Parameters

array $item: Taxonomy menu item.

Return value

array Taxonomy menu item.

2 calls to _taxonomy_menu_item()
taxonomy_menu_taxonomy_menu_insert in ./taxonomy_menu.module
Implements hook_taxonomy_menu_insert().
taxonomy_menu_taxonomy_menu_update in ./taxonomy_menu.module
Implements hook_taxonomy_menu_update().

File

./taxonomy_menu.module, line 967
Adds links to taxonomy terms into a menu.

Code

function _taxonomy_menu_item($item) {
  if (empty($item)) {
    return;
  }

  // If tid is 0 then do not change any settings.
  if ($item['tid'] > 0) {

    // Get the number of node attached to this term.
    $num = _taxonomy_menu_term_count($item['tid']);

    // If hide menu is selected and the term count is 0 and the term has no
    // children then do not create the menu item.
    if ($num == 0 && variable_get(_taxonomy_menu_build_variable('hide_empty_terms', $item['vid']), FALSE) && !_taxonomy_menu_children_has_nodes($item['tid'], $item['vid'])) {
      $item['remove'] = TRUE;
      return $item;
    }

    // If display number is selected and $num > 0 then change the title.
    if (variable_get(_taxonomy_menu_build_variable('display_num', $item['vid']), FALSE)) {

      // If number > 0 and display include children num, then count all of the children.
      if (variable_get(_taxonomy_menu_build_variable('display_num_incl_children', $item['vid']), TRUE)) {
        $num = taxonomy_menu_term_count_nodes($item['tid'], $item['vid']);
      }
      $item['name'] .= " ({$num})";
    }
  }
  elseif ($item['tid'] == 0) {

    // If custom name is provided, use that name.
    $custom_name = variable_get(_taxonomy_menu_build_variable('voc_name', $item['vid']), '');
    if (!empty($custom_name)) {
      $item['name'] = $custom_name;
    }
  }
  return $item;
}