public function TranslationLanguageRenderer::query in Drupal 9
Same name and namespace in other branches
- 8 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 24
Class
- TranslationLanguageRenderer
- Renders entity translations in their row language.
Namespace
Drupal\views\Entity\RenderCode
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_table = $this
->getLangcodeTable($query, $relationship);
if ($langcode_table) {
/** @var \Drupal\views\Plugin\views\query\Sql $query */
$table_alias = $query
->ensureTable($langcode_table, $relationship);
$langcode_key = $this->entityType
->getKey('langcode');
$this->langcodeAlias = $query
->addField($table_alias, $langcode_key);
}
}