Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 25 |
| CurrentLanguageContext | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 25 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getRuntimeContexts | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 21 |
|||
| getAvailableContexts | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\Core\Language\ContextProvider\CurrentLanguageContext. | |
| */ | |
| namespace Drupal\Core\Language\ContextProvider; | |
| use Drupal\Core\Cache\CacheableMetadata; | |
| use Drupal\Core\Language\LanguageManagerInterface; | |
| use Drupal\Core\Plugin\Context\Context; | |
| use Drupal\Core\Plugin\Context\ContextDefinition; | |
| use Drupal\Core\Plugin\Context\ContextProviderInterface; | |
| use Drupal\Core\StringTranslation\StringTranslationTrait; | |
| /** | |
| * Sets the current language as a context. | |
| */ | |
| class CurrentLanguageContext implements ContextProviderInterface { | |
| use StringTranslationTrait; | |
| /** | |
| * The language manager. | |
| * | |
| * @var \Drupal\Core\Language\LanguageManagerInterface | |
| */ | |
| protected $languageManager; | |
| /** | |
| * Constructs a new CurrentLanguageContext. | |
| * | |
| * @param \Drupal\Core\Language\LanguageManagerInterface | |
| * The language manager. | |
| */ | |
| public function __construct(LanguageManagerInterface $language_manager) { | |
| $this->languageManager = $language_manager; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| 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; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function getAvailableContexts() { | |
| return $this->getRuntimeContexts([]); | |
| } | |
| } |