You are here

function _taxonomy_menu_trails_process in Taxonomy Menu Trails 6.x

Same name and namespace in other branches
  1. 6 taxonomy_menu_trails.inc \_taxonomy_menu_trails_process()
  2. 7.2 taxonomy_menu_trails.inc \_taxonomy_menu_trails_process()
  3. 7 taxonomy_menu_trails.inc \_taxonomy_menu_trails_process()
1 call to _taxonomy_menu_trails_process()
taxonomy_menu_trails_init in ./taxonomy_menu_trails.module
Implementation of hook_init().

File

./taxonomy_menu_trails.inc, line 19
Processing functions for taxonomy_menu_trails.

Code

function _taxonomy_menu_trails_process($node, $item) {
  $types = variable_get('taxonomy_menu_trails_node_types', array());
  $vids = $types[$node->type];
  $taxonomy = $node->taxonomy;
  $selected_term = NULL;
  $selected_href = NULL;
  switch (variable_get('taxonomy_menu_trails_selection_method', 'first')) {
    case 'first':
      for ($term = reset($taxonomy); $term !== FALSE; $term = next($taxonomy)) {
        if (in_array($term->vid, $vids)) {
          $selected_term = $term;
          break;
        }
      }
      break;
    case 'last':
      for ($term = end($taxonomy); $term !== FALSE; $term = prev($taxonomy)) {
        if (in_array($term->vid, $vids)) {
          $selected_term = $term;
          break;
        }
      }
      break;
    case 'first-with-menu':
      for ($term = reset($taxonomy); $term !== FALSE; $term = next($taxonomy)) {
        if (in_array($term->vid, $vids)) {
          $href = _taxonomy_menu_trails_get_path($term);
          if (db_result(db_query('SELECT COUNT(*) FROM {menu_links} WHERE link_path = "%s" AND hidden = 0', $href)) > 0) {
            $selected_term = $term;
            $selected_href = $href;
            break;
          }
        }
      }
      break;
    case 'last-with-menu':
      for ($term = end($taxonomy); $term !== FALSE; $term = prev($taxonomy)) {
        if (in_array($term->vid, $vids)) {
          $href = _taxonomy_menu_trails_get_path($term);
          if (db_result(db_query('SELECT COUNT(*) FROM {menu_links} WHERE link_path = "%s" AND hidden = 0', $href)) > 0) {
            $selected_term = $term;
            $selected_href = $href;
            break;
          }
        }
      }
      break;
    case 'deepest-in-lineage':
      $selected_term = _taxonomy_menu_trails_get_deepest_term($node, $vids);
      break;
    default:
      return;
  }
  if (!$selected_term) {
    return;
  }
  if ($selected_href === NULL) {
    $selected_href = _taxonomy_menu_trails_get_path($selected_term);
  }
  $item['href'] = $selected_href;
  menu_set_item(NULL, $item);
}