You are here

function i18ntaxonomy_nodeapi in Internationalization 6

Same name and namespace in other branches
  1. 5.3 contrib/i18ntaxonomy.module \i18ntaxonomy_nodeapi()
  2. 5 contrib/i18ntaxonomy.module \i18ntaxonomy_nodeapi()
  3. 5.2 contrib/i18ntaxonomy.module \i18ntaxonomy_nodeapi()

Implementation of hook_nodeapi().

Prepare node for translation.

File

i18ntaxonomy/i18ntaxonomy.module, line 699
i18n taxonomy module

Code

function i18ntaxonomy_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'view':

      // This runs after taxonomy:nodeapi, so we just localize terms here.
      if (!empty($node->taxonomy)) {
        $node->taxonomy = i18ntaxonomy_localize_terms($node->taxonomy);
      }
      if ($node->type == 'forum' && ($vid = variable_get('forum_nav_vocabulary', '')) && i18ntaxonomy_vocabulary($vid)) {
        if ($page && taxonomy_node_get_terms_by_vocabulary($node, $vid) && ($tree = taxonomy_get_tree($vid))) {

          // Breadcrumb navigation
          $vocabulary = taxonomy_vocabulary_load($vid);
          $breadcrumb[] = l(t('Home'), NULL);
          $breadcrumb[] = l(i18nstrings("taxonomy:vocabulary:{$vid}:name", $vocabulary->name), 'forum');

          // Translate node taxonomy terms. Sometimes there are no terms, like for search results...
          if (!empty($node->taxonomy)) {

            // Get the forum terms from the (cached) tree
            foreach ($tree as $term) {
              $forum_terms[] = $term->tid;
            }
            foreach ($node->taxonomy as $term_id => $term) {
              if (in_array($term_id, $forum_terms)) {
                $node->tid = $term_id;
              }
            }
            if ($parents = taxonomy_get_parents_all($node->tid)) {
              $parents = array_reverse($parents);
              foreach ($parents as $p) {
                $breadcrumb[] = l(i18nstrings("taxonomy:term:{$term->tid}:name", $p->name), 'forum/' . $p->tid);
              }
            }
          }
          drupal_set_breadcrumb($breadcrumb);
        }
      }
      break;
    case 'prepare translation':
      $source = $node->translation_source;

      // Taxonomy translation.
      if (is_array($source->taxonomy)) {

        // Set translated taxonomy terms.
        $node->taxonomy = i18ntaxonomy_translate_terms($source->taxonomy, $node->language);
      }
      break;
  }
}