home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (views_handler_field_node_translation_link.inc)

This example Drupal source code file (views_handler_field_node_translation_link.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

extends, function, if, isset, language, node, php, render, return, title, tnid, translations, true, values

The views_handler_field_node_translation_link.inc Drupal example source code

<?php
// $Id: views_handler_field_node_translation_link.inc,v 1.1.6.3 2010/12/09 21:45:49 dereine Exp $
/**
 * Field handler to present a link to the node.
 */
class views_handler_field_node_translation_link extends views_handler_field {
  function construct() {
    parent::construct();
    $this->additional_fields['nid'] = 'nid';
    $this->additional_fields['tnid'] = 'tnid';
    $this->additional_fields['title'] = 'title';
    $this->additional_fields['language'] = 'language';
  }

  function query() {
    $this->ensure_my_table();
    $this->add_additional_fields();
  }

  function render($values) {
    return $this->render_link(check_plain($values->{$this->aliases['tnid']}), $values);
  }

  function render_link($data, $values) {
    global $language;
    $tnid = $values->{$this->aliases['tnid']};
    // Only load translations if the node isn't in the current language.
    if ($values->{$this->aliases['language']} != $language->language) {
      $translations = translation_node_get_translations($tnid);
      if (isset($translations[$language->language])) {
        $values->{$this->aliases['nid']} = $translations[$language->language]->nid;
        $values->{$this->aliases['title']} = $translations[$language->language]->title;
      }
    }

    $this->options['alter']['make_link'] = TRUE;
    $this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']};
    return $values->{$this->aliases['title']};
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal views_handler_field_node_translation_link.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.