You are here

public function TranslationLanguageRenderer::query in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php \Drupal\views\Entity\Render\TranslationLanguageRenderer::query()

Alters the query if needed.

Parameters

\Drupal\views\Plugin\views\query\QueryPluginBase $query: The query to alter.

string $relationship: (optional) The relationship, used by a field.

Overrides EntityTranslationRendererBase::query

File

core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php, line 29
Contains \Drupal\views\Entity\Render\TranslationLanguageRenderer.

Class

TranslationLanguageRenderer
Renders entity translations in their row language.

Namespace

Drupal\views\Entity\Render

Code

public function query(QueryPluginBase $query, $relationship = NULL) {

  // In order to render in the translation language of the entity, we need
  // to add the language code of the entity to the query. Skip if the site
  // is not multilingual or the entity is not translatable.
  if (!$this->languageManager
    ->isMultilingual() || !$this->entityType
    ->hasKey('langcode')) {
    return;
  }
  $langcode_key = $this->entityType
    ->getKey('langcode');
  $storage = \Drupal::entityManager()
    ->getStorage($this->entityType
    ->id());
  if ($table = $storage
    ->getTableMapping()
    ->getFieldTableName($langcode_key)) {
    $table_alias = $query
      ->ensureTable($table, $relationship);
    $this->langcodeAlias = $query
      ->addField($table_alias, $langcode_key);
  }
}