You are here

Language.php in Views (for Drupal 7) 8.3

File

lib/Views/node/Plugin/views/field/Language.php
View source
<?php

/**
 * @file
 * Definition of Views\node\Plugin\views\field\Language.
 */
namespace Views\node\Plugin\views\field;

use Views\node\Plugin\views\field\Node;
use Drupal\Core\Annotation\Plugin;

/**
 * Field handler to translate a language into its readable form.
 *
 * @ingroup views_field_handlers
 *
 * @Plugin(
 *   id = "node_language",
 *   module = "node"
 * )
 */
class Language extends Node {
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['native_language'] = array(
      'default' => FALSE,
      'bool' => TRUE,
    );
    return $options;
  }
  public function buildOptionsForm(&$form, &$form_state) {
    parent::buildOptionsForm($form, $form_state);
    $form['native_language'] = array(
      '#title' => t('Native language'),
      '#type' => 'checkbox',
      '#default_value' => $this->options['native_language'],
      '#description' => t('If enabled, the native name of the language will be displayed'),
    );
  }
  function render($values) {

    // @todo: Drupal Core dropped native language until config translation is
    // ready, see http://drupal.org/node/1616594.
    $value = $this
      ->get_value($values);
    $language = language_load($value);
    $value = $language ? $language->name : '';
    return $this
      ->render_link($value, $values);
  }

}

Classes

Namesort descending Description
Language Field handler to translate a language into its readable form.