You are here

trait TranslationViewsTargetLanguage in Translation Views 8

Trait TranslationViewsTargetLanguage.

Used to give ability to get selected target langcode, used by different different fields, filters.

@package Drupal\translation_views

Hierarchy

5 files declare their use of TranslationViewsTargetLanguage
TranslationModerationState.php in src/Plugin/views/field/TranslationModerationState.php
TranslationOperationsField.php in src/Plugin/views/field/TranslationOperationsField.php
TranslationStatus.php in src/Plugin/views/field/TranslationStatus.php
TranslationTargetLanguageField.php in src/Plugin/views/field/TranslationTargetLanguageField.php
TranslationTargetLanguageFilter.php in src/Plugin/views/filter/TranslationTargetLanguageFilter.php

File

src/TranslationViewsTargetLanguage.php, line 15

Namespace

Drupal\translation_views
View source
trait TranslationViewsTargetLanguage {

  /**
   * The language manager.
   *
   * @var \Drupal\Core\Language\LanguageManagerInterface
   */
  protected $languageManager;

  /**
   * Target exposed key.
   *
   * @var string
   */
  public static $targetExposedKey = 'translation_target_language';

  /**
   * Get target language from exposed input.
   *
   * @return string
   *   The selected target langcode.
   */
  protected function getTargetLangcode() {
    $inputs = $this->view
      ->getExposedInput();
    $langcode = isset($inputs[self::$targetExposedKey]) ? $inputs[self::$targetExposedKey] : PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT;
    return $langcode == PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT ? $this->languageManager
      ->getDefaultLanguage()
      ->getId() : $langcode;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TranslationViewsTargetLanguage::$languageManager protected property The language manager.
TranslationViewsTargetLanguage::$targetExposedKey public static property Target exposed key.
TranslationViewsTargetLanguage::getTargetLangcode protected function Get target language from exposed input.