You are here

function taxonomy_menu_translated_menu_link_alter in Taxonomy menu 6.2

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

Implementation of hook_translated_menu_link_alter().

Translate menu links on the fly by using term translations.

File

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

Code

function taxonomy_menu_translated_menu_link_alter(&$item, $map) {
  if (module_exists('i18ntaxonomy')) {

    // in case of localized terms, use term translation for menu title
    if ($item['module'] == 'taxonomy_menu') {

      // @todo check vocabulary translation mode before tryring to translate: but is this really usefull ?
      //  if (i18ntaxonomy_vocabulary($vid) == I18N_TAXONOMY_LOCALIZE) {
      $t = _taxonomy_menu_get_item($item['mlid']);
      if ($t['tid'] > 0) {

        // this is a term
        $term = taxonomy_get_term($t['tid']);
        if (!$term) {
          $info = array(
            'tid' => $t['tid'],
            'vid' => $t['vid'],
            'mlid' => $item['mlid'],
          );

          // menu items from taxonomy menu module can not be deleted manually
          taxonomy_menu_taxonomy_menu_delete($info);
          watchdog('error', 'You deleted a term, but not the corresponding menu item @menuitem. The menu item was deleted.', array(
            '@menuitem' => $item['title'],
          ));
          return;
        }
        $display_num = '';
        $num = _taxonomy_menu_term_count($t['tid']);

        // if hide menu is selected and the term count is 0 and the term has no children then do not create the menu item
        if ($num == 0 && variable_get('taxonomy_menu_hide_empty_terms_' . $t['vid'], FALSE) && !_taxonomy_menu_children_has_nodes($t['tid'], $t['vid'])) {
          $display_num = '';
        }
        elseif (variable_get('taxonomy_menu_display_num_' . $t['vid'], FALSE)) {

          // if number > 0 and display decendants, then count all of the children
          if (variable_get('taxonomy_menu_display_descendants_' . $t['vid'], FALSE)) {
            $num = taxonomy_term_count_nodes($t['tid']);
          }
          $display_num = " ({$num})";
        }

        // Run the name through check_plain
        $title = tt('taxonomy:term:' . $term->tid . ':name', $term->name . $display_num);
        if ($item['title'] != $term->name . $display_num) {

          // Should not happen
          watchdog('error', t('Menu and taxonomy name mismatch: @title != @name', array(
            '@title' => $item['title'],
            '@name' => $term->name . $display_num,
          )));
        }
      }
      else {

        // is a vocabulary
        $vocab = taxonomy_vocabulary_load($t['vid']);
        $title = tt('taxonomy:vocabulary:' . $vocab->vid . ':name', $vocab->name);
      }

      // Set the title
      $item['link_title'] = $title;
      $item['title'] = $title;
    }
  }
}