function PluginBase::queryLanguageSubstitutions

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

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.