You are here

taxonomy_menu.module in Taxonomy menu 6

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

File

taxonomy_menu.module
View source
<?php

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

// Some "magic numbers" revealed
define('TAXONOMY_MENU_NONE', 0);
define('TAXONOMY_MENU_NORMAL', 1);
define('TAXONOMY_MENU_VIEW', 2);
define('TAXONOMY_MENU_DEFAULT_TAX', 3);

/**
 * Implementation of hook_menu().
 *
 * Its the main function for this module.
 */
function taxonomy_menu_menu() {
  require_once drupal_get_path('module', 'taxonomy_menu') . '/taxonomy_menu.inc';
  return _taxonomy_menu_menu();
}

/**
 * Implementation of hook_nodeapi().
 *
 * This hook enables the menu to be displayed in context during node views.
 */
function taxonomy_menu_nodeapi(&$node, $op, $a3, $a4) {
  static $vocabs = array();

  // First check if the node has a relevant category.s
  if (empty($vocabs) and is_array($vocabs)) {
    $terms = taxonomy_node_get_terms($node);

    // The node should have taxonomy terms
    if (empty($terms)) {
      return;
    }

    // Check if at least one vocabulary is revelevant
    // for us, being a menu
    foreach ($terms as $term) {
      if (variable_get('taxonomy_menu_show_' . $term->vid, TAXONOMY_MENU_NONE)) {
        $vocabs[$term->vid][] = $term->tid;
      }
    }

    // If none of the terms are tracked by this module,
    // forget it
    if (empty($vocabs)) {
      $vocabs = FALSE;
      return;
    }
  }
  if ($op == 'view' and $a4 == TRUE and !empty($vocabs)) {
    require_once drupal_get_path('module', 'taxonomy_menu') . '/taxonomy_menu.inc';
    _taxonomy_menu_node_view($node, $vocabs);
  }
  elseif ($op == 'update' or $op == 'insert' or $op == 'delete') {
    variable_set('menu_rebuild_needed', TRUE);
  }
}

/**
 * Implementation of hook_taxonomy().
 *
 * Invalidates the menu cache on taxonomy changes.
 */
function taxonomy_menu_taxonomy() {
  variable_set('menu_rebuild_needed', TRUE);
}