You are here

function _taxonomy_menu_menu in Taxonomy menu 5

Same name and namespace in other branches
  1. 6 taxonomy_menu.inc \_taxonomy_menu_menu()

Implementation of hook_menu().

Its the main function for this module.

1 call to _taxonomy_menu_menu()
taxonomy_menu_menu in ./taxonomy_menu.module
Implementation of hook_menu().

File

./taxonomy_menu.inc, line 119
taxonomy_menu.inc @author Jonathan Chaffer <jchaffer@structureinteractive.com> @author Bruno Massa <http://drupal.org/user/67164> It Generates menu links for all taxonomy terms

Code

function _taxonomy_menu_menu() {
  if (module_exists('pathauto')) {
    $pathauto_exists = true;
    _pathauto_include();
  }
  $items['admin/settings/taxonomy_menu'] = array(
    'access' => user_access('administer site configuration'),
    'callback' => 'drupal_get_form',
    'callback arguments' => array(
      '__taxonomy_menu_admin',
    ),
    'file' => 'taxonomy_menu.inc',
    'description' => t('Global configuration of taxonomy menu functionality.'),
    'path' => 'admin/settings/taxonomy_menu',
    'title' => t('Taxonomy Menu'),
    'type' => MENU_NORMAL_ITEM,
  );

  // This user access function will be used for
  // all menu items
  $access = user_access('access content');
  foreach (taxonomy_get_vocabularies() as $vocabulary) {
    if (variable_get('taxonomy_menu_show_' . $vocabulary->vid, TAXONOMY_MENU_NONE)) {

      //  $path =  variable_get('taxonomy_menu_display_page', 'category') .'/'. $vocabulary->vid;
      if (variable_get('taxonomy_menu_hide_module_page', FALSE)) {
        $path = $vocabulary->vid;
      }
      else {
        $path = variable_get('taxonomy_menu_display_page', 'category') . '/' . $vocabulary->vid;
      }
      $items[$path] = array(
        'access' => $access,
        'callback' => '__taxonomy_menu_page',
        'file' => 'taxonomy_menu.inc',
        'page callback' => '__taxonomy_menu_page',
        'path' => $path,
        'title' => t($vocabulary->name),
        'weight' => $vocabulary->weight,
      );
      if ($pathauto_exists) {
        $placeholders = pathauto_get_placeholders('taxonomy', $vocabulary);
        $alias = pathauto_create_alias('taxonomy_menu', 'update', $placeholders, $path, $vocabulary->vid);
      }
      $tree = taxonomy_get_tree($vocabulary->vid);
      $old_depth = -1;
      $old_path = $path;
      if ($pathauto_exists) {
        $placeholders = pathauto_get_placeholders('taxonomy', $term);
        $alias = pathauto_create_alias('taxonomy_menu', 'update', $placeholders, $path, $term->tid);
      }
      foreach ($tree as $term) {
        if ($term->depth <= $old_depth) {
          $slashes_to_remove = $old_depth - $term->depth + 1;
          for ($i = 0; $i < $slashes_to_remove; $i++) {
            $old_path = substr($old_path, 0, strrpos($old_path, '/'));
          }
        }
        $path = $old_path . '/' . $term->tid;
        $old_depth = $term->depth;
        $old_path = $path;

        // Calculate the numbers of children nodes
        $num = taxonomy_term_count_nodes($term->tid);

        // If the number of children nodes of this term is
        // zero and the Hide Empty Terms option is enabled,
        // dont create the menu item
        if (variable_get('taxonomy_menu_hide_empty', FALSE) == FALSE or $num != 0) {
          $name = t($term->name);
          if (variable_get('taxonomy_menu_display_num', FALSE) == TRUE) {
            $name .= ' (' . $num . ')';
          }
          $items[$path] = array(
            'access' => $access,
            'callback' => '__taxonomy_menu_page',
            'description' => t($term->description),
            'file' => 'taxonomy_menu.inc',
            'page callback' => '__taxonomy_menu_page',
            'path' => $path,
            'title' => $name,
            'weight' => $term->weight,
          );
        }
      }
    }
  }
  return $items;
}