You are here

function entity_translation_node_view in Entity Translation 7

Implements hook_node_view().

Provides content language switcher links to navigate among node translations.

File

./entity_translation.node.inc, line 91
The node specific translation functions and hook implementations.

Code

function entity_translation_node_view($node, $build_mode, $langcode) {
  if (!empty($node->translations) && drupal_multilingual() && entity_translation_node_supported_type($node->type) && !variable_get("entity_translation_hide_translation_links_{$node->type}", FALSE)) {
    $path = 'node/' . $node->nid;
    $links = EntityTranslationDefaultHandler::languageSwitchLinks($path);
    if (is_object($links) && !empty($links->links)) {
      $handler = entity_translation_get_handler('node', $node);
      $translations = $handler
        ->getTranslations()->data;

      // Remove the link for the current language.
      unset($links->links[$langcode]);

      // Remove links to unavailable translations.
      foreach ($links->links as $langcode => $link) {
        if (!isset($translations[$langcode]) || !entity_translation_access('node', $translations[$langcode])) {
          unset($links->links[$langcode]);
        }
      }
      $node->content['links']['translation'] = array(
        '#theme' => 'links',
        '#links' => $links->links,
        '#attributes' => array(
          'class' => 'links inline',
        ),
      );
    }
  }
}