You are here

function taxonomy_menu_nodeapi in Taxonomy menu 6.2

Same name and namespace in other branches
  1. 5 taxonomy_menu.module \taxonomy_menu_nodeapi()
  2. 6 taxonomy_menu.module \taxonomy_menu_nodeapi()

Implementation of hook_nodeapi().

This hook enables the menu to be displayed in context during node views.

File

./taxonomy_menu.module, line 337
It Generates menu links for all selected taxonomy terms

Code

function taxonomy_menu_nodeapi(&$node, $op, $a3, $a4) {
  static $terms_old;
  switch ($op) {
    case 'insert':
    case 'update':

      // we use this direct table pull to avoid the cache and because
      // free tags are not formated in a matter where extrating the
      // tid's is easy
      $terms_new = _taxonomy_menu_get_node_terms($node->nid);

      // merge current terms and previous terms to update both menu items.
      $terms = array_unique(array_merge((array) $terms_new, (array) $terms_old));
      _taxonomy_menu_nodeapi_helper($op, $terms);
      break;
    case 'presave':

      // get the terms from the database before the changes are made.
      // these will be used to update the menu item's name if needed
      // we go directly to the db to bypass any caches
      $terms_old = _taxonomy_menu_get_node_terms($node->nid);
      break;
    case 'delete':

      // since the delete operation is run after the data is deleted
      // pull the terms from the node object
      $terms = array_keys($node->taxonomy);
      _taxonomy_menu_nodeapi_helper($op, $terms);
      break;
  }
}