You are here

function _taxonomy_menu_nodeapi_helper in Taxonomy menu 6.2

Same name and namespace in other branches
  1. 8 taxonomy_menu.module \_taxonomy_menu_nodeapi_helper()
  2. 7.2 taxonomy_menu.module \_taxonomy_menu_nodeapi_helper()
  3. 7 taxonomy_menu.module \_taxonomy_menu_nodeapi_helper()

Helper function to

1 call to _taxonomy_menu_nodeapi_helper()
taxonomy_menu_nodeapi in ./taxonomy_menu.module
Implementation of hook_nodeapi().

File

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

Code

function _taxonomy_menu_nodeapi_helper($op, $terms = array()) {
  foreach ($terms as $key => $tid) {
    $term = taxonomy_get_term($tid);
    $term->parents = array_keys(taxonomy_get_parents($tid));

    // $parents = taxonomy_get_parents($tid);
    // foreach ($parents as $term_id => $term_obj) {
    //   $term->parents[] = $term_id;
    // }
    // update the menu for each term if necessary
    $menu_name = variable_get('taxonomy_menu_vocab_menu_' . $term->vid, FALSE);
    $vocb_sync = variable_get('taxonomy_menu_sync_' . $term->vid, TRUE);
    $menu_num = variable_get('taxonomy_menu_display_num_' . $term->vid, FALSE);
    $hide_empty = variable_get('taxonomy_menu_hide_empty_terms_' . $term->vid, FALSE);
    if ($menu_name && $vocb_sync && ($menu_num || $hide_empty)) {
      switch ($op) {
        case 'update':

          // build argument array to save menu_item
          $args = array(
            'tid' => $term->tid,
            'vid' => $term->vid,
            'term' => $term,
            'menu_name' => $menu_name,
            'mlid' => _taxonomy_menu_get_mlid($term->tid, $term->vid),
          );

          // since taxonomy_get_term does not return the parents, fetch them now
          $args['term']->parents = _taxonomy_menu_get_parents($term->tid);
          break;
        case 'insert':

          // build argument array to save menu_item
          $args = array(
            'tid' => $term->tid,
            'vid' => $term->vid,
            'term' => $term,
            'menu_name' => $menu_name,
            'mlid' => _taxonomy_menu_get_mlid($term->tid, $term->vid),
          );

          // since taxonomy_get_term does not return the parents, fetch them now
          $args['term']->parents = _taxonomy_menu_get_parents($term->tid);
          break;
        case 'delete':
          $args = array(
            'term' => $term,
            'tid' => $term->tid,
            'vid' => $term->vid,
            'menu_name' => $menu_name,
            'mlid' => _taxonomy_menu_get_mlid($term->tid, $term->vid),
          );

          /* Turn the op to 'update' here since we really do want to update the item
           * and not delete/recreate it, since the latter will break hierarchy and
           * customizations.
           */
          $op = 'update';
      }
      taxonomy_menu_handler($op, $args);
    }
  }
}