You are here

public function TranslationLanguageRenderer::query in Display Suite 8.4

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/Entity/Render/TranslationLanguageRenderer.php \Drupal\ds\Plugin\views\Entity\Render\TranslationLanguageRenderer::query()
  2. 8.3 src/Plugin/views/Entity/Render/TranslationLanguageRenderer.php \Drupal\ds\Plugin\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

src/Plugin/views/Entity/Render/TranslationLanguageRenderer.php, line 23

Class

TranslationLanguageRenderer
Renders entities in the current language.

Namespace

Drupal\ds\Plugin\views\Entity\Render

Code

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

  // There is no point in getting the language, in case the site is not
  // multilingual.
  if (!$this->languageManager
    ->isMultilingual()) {
    return;
  }

  // If the data table is defined, we use the translation language as render
  // language, otherwise we fall back to the default entity language, which is
  // stored in the revision table for revisionable entity types.
  $langcode_key = $this->entityType
    ->getKey('langcode');
  foreach ([
    'data_table',
    'revision_table',
    'base_table',
  ] as $key) {
    if ($table = $this->entityType
      ->get($key)) {
      $table_alias = $query
        ->ensureTable($table);
      $this->langcodeAlias = $query
        ->addField($table_alias, $langcode_key);
      break;
    }
  }
}