You are here

function i18n_translation_link_alter in Internationalization 6

Implementation of hook_alter_translation_link().

Handles links for extended language. The links will have current language.

File

./i18n.module, line 196
Internationalization (i18n) module.

Code

function i18n_translation_link_alter(&$links, $path) {
  global $language;

  // Check for a node related path, and for its translations.
  if (preg_match("!^node/([0-9]+)(/.+|)\$!", $path, $matches) && ($node = node_load((int) $matches[1])) && !empty($node->tnid)) {

    // make sure language support is set to LANGUAGE_SUPPORT_EXTENDED, so links
    // dont get added for LANGUAGE_SUPPORT_EXTENDED_NOT_DISPLAYED
    if (variable_get('i18n_node_' . $node->type, LANGUAGE_SUPPORT_NORMAL) == LANGUAGE_SUPPORT_EXTENDED) {
      $languages = language_list();
      $extended = array();
      foreach (translation_node_get_translations($node->tnid) as $langcode => $translation_node) {
        if (!isset($links[$langcode]) && isset($languages[$langcode])) {
          $extended[$langcode] = array(
            'href' => 'node/' . $translation_node->nid . $matches[2],
            'language' => $language,
            'language_icon' => $languages[$langcode],
            'title' => $languages[$langcode]->native,
            'attributes' => array(
              'class' => 'language-link',
            ),
          );
        }
      }

      // This will run after languageicon module, so we add icon in case that one is enabled.
      if ($extended && function_exists('languageicons_translation_link_alter')) {
        languageicons_translation_link_alter($extended, $path);
      }
      $links = array_merge($links, $extended);
    }
  }
}