function CurrentLanguageContext::getRuntimeContexts
Same name in other branches
- 9 core/lib/Drupal/Core/Language/ContextProvider/CurrentLanguageContext.php \Drupal\Core\Language\ContextProvider\CurrentLanguageContext::getRuntimeContexts()
- 8.9.x core/lib/Drupal/Core/Language/ContextProvider/CurrentLanguageContext.php \Drupal\Core\Language\ContextProvider\CurrentLanguageContext::getRuntimeContexts()
- 11.x core/lib/Drupal/Core/Language/ContextProvider/CurrentLanguageContext.php \Drupal\Core\Language\ContextProvider\CurrentLanguageContext::getRuntimeContexts()
Overrides ContextProviderInterface::getRuntimeContexts
1 call to CurrentLanguageContext::getRuntimeContexts()
- CurrentLanguageContext::getAvailableContexts in core/
lib/ Drupal/ Core/ Language/ ContextProvider/ CurrentLanguageContext.php - Gets all available contexts for the purposes of configuration.
File
-
core/
lib/ Drupal/ Core/ Language/ ContextProvider/ CurrentLanguageContext.php, line 39
Class
- CurrentLanguageContext
- Sets the current language as a context.
Namespace
Drupal\Core\Language\ContextProviderCode
public function getRuntimeContexts(array $unqualified_context_ids) {
// Add a context for each language type.
$language_types = $this->languageManager
->getLanguageTypes();
$info = $this->languageManager
->getDefinedLanguageTypesInfo();
if ($unqualified_context_ids) {
foreach ($unqualified_context_ids as $unqualified_context_id) {
if (array_search($unqualified_context_id, $language_types) === FALSE) {
unset($language_types[$unqualified_context_id]);
}
}
}
$result = [];
foreach ($language_types as $type_key) {
if (isset($info[$type_key]['name'])) {
$context = new Context(new ContextDefinition('language', $info[$type_key]['name']), $this->languageManager
->getCurrentLanguage($type_key));
$cacheability = new CacheableMetadata();
$cacheability->setCacheContexts([
'languages:' . $type_key,
]);
$context->addCacheableDependency($cacheability);
$result[$type_key] = $context;
}
}
return $result;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.