You are here

function i18n_node_node_view_alter in Internationalization 7

Implements hook_node_view_alter().

Handles links for extended languages. Sets current interface language.

File

i18n_node/i18n_node.module, line 278
Internationalization (i18n) module - Node type handling

Code

function i18n_node_node_view_alter(&$build) {
  if (isset($build['#node'])) {
    $node = $build['#node'];
  }

  // Hide node translation links.
  if (variable_get('i18n_hide_translation_links', 0)) {
    if (isset($build['links']['translation'])) {
      unset($build['links']['translation']);
    }
  }
  elseif (!empty($node->tnid) && !empty($build['links']['translation']) && i18n_node_language_mode($node) == I18N_LANGUAGE_EXTENDED) {

    // We only get links for translations for enabled languages
    // Set the right languages if language support is extended but not visible.
    $links =& $build['links']['translation']['#links'];
    $translations = translation_node_get_translations($node->tnid);
    foreach (i18n_node_language_list($node) as $langcode => $langname) {
      $index = 'translation_' . $langcode;
      if ($langcode != $node->language && isset($translations[$langcode]) && $translations[$langcode]->status && !isset($links[$index])) {

        // This a published translation to a disabled language. As the node is language extended, display the linkso
        // These links shouldn't switch the interface, though they have a language so the right language icon will be added
        $language = i18n_language_object($langcode);
        $links[$index] = array(
          'href' => 'node/' . $translations[$langcode]->nid,
          'title' => $language->native,
          'language' => $language,
          'attributes' => array(
            'title' => $translations[$langcode]->title,
            'class' => array(
              'translation-link',
            ),
          ),
        );
      }
    }
  }
}