You are here

public static function PluginBase::queryLanguageSubstitutions in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase::queryLanguageSubstitutions()
  2. 10 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.

1 call to PluginBase::queryLanguageSubstitutions()
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 633

Class

PluginBase
Base class for any views plugin types.

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;
}