You are here

public static function PluginBase::queryLanguageSubstitutions in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase::queryLanguageSubstitutions()
  2. 9 core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase::queryLanguageSubstitutions()

Returns substitutions for Views queries for languages.

This is needed so that the language options returned by PluginBase::listLanguages() are able to be used in queries. It is called by the Views module implementation of hook_views_query_substitutions() to get the language-related substitutions.

Return value

array An array in the format of hook_views_query_substitutions() that gives the query substitutions needed for the special language types.

2 calls to PluginBase::queryLanguageSubstitutions()
EntityTranslationRenderTrait::getEntityTranslationRenderer in core/modules/views/src/Entity/Render/EntityTranslationRenderTrait.php
Returns the current renderer.
views_views_query_substitutions in core/modules/views/views.views_execution.inc
Implements hook_views_query_substitutions().

File

core/modules/views/src/Plugin/views/PluginBase.php, line 632

Class

PluginBase

Namespace

Drupal\views\Plugin\views

Code

public static function queryLanguageSubstitutions() {
  $changes = [];
  $manager = \Drupal::languageManager();

  // Handle default language.
  $default = $manager
    ->getDefaultLanguage()
    ->getId();
  $changes[PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT] = $default;

  // Handle negotiated languages.
  $types = $manager
    ->getDefinedLanguageTypesInfo();
  foreach ($types as $id => $type) {
    if (isset($type['name'])) {
      $changes['***LANGUAGE_' . $id . '***'] = $manager
        ->getCurrentLanguage($id)
        ->getId();
    }
  }
  return $changes;
}