You are here

function faq_link_alter in Frequently Asked Questions 6

Same name and namespace in other branches
  1. 5.2 faq.module \faq_link_alter()

Implements hook_link_alter().

Change the term links on a node to point at the appropriate faq page.

File

./faq.module, line 1065
The FAQ module allows users to create a FAQ page, with questions and answers displayed in different styles, according to the settings.

Code

function faq_link_alter(&$links, $node) {
  static $vocabularies;
  if ($node->type != 'faq' || !variable_get('faq_use_categories', FALSE) || !module_exists("taxonomy") || !variable_get('faq_enable_term_links', 1)) {
    return;
  }
  if (!isset($vocabularies)) {
    $vocabularies = taxonomy_get_vocabularies('faq');
    $vocab_omit = array_flip(variable_get('faq_omit_vocabulary', array()));
    $vocabularies = array_diff_key($vocabularies, $vocab_omit);
  }
  foreach ($links as $module => $link) {
    if (strpos($module, 'taxonomy_term') !== FALSE) {

      // Link back to the faq and not the taxonomy term page. We'll only
      // do this if the taxonomy term in question belongs to faq vocab.
      $tid = str_replace('taxonomy/term/', '', $link['href']);
      $term = taxonomy_get_term($tid);
      if (!is_object($term)) {
        continue;
      }
      foreach ($vocabularies as $vid => $vobj) {
        if ($term->vid == $vid && taxonomy_term_count_nodes($term->tid, 'faq')) {
          $links[$module]['href'] = str_replace('taxonomy/term', 'faq', $link['href']);
          break;
        }
      }
    }
  }
}