class LanguageInterfaceContext in Page Manager 8.4
Sets the current language_interface as a context.
Hierarchy
- class \Drupal\page_manager\EventSubscriber\LanguageInterfaceContext implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of LanguageInterfaceContext
1 file declares its use of LanguageInterfaceContext
- LanguageInterfaceContextTest.php in tests/
src/ Unit/ LanguageInterfaceContextTest.php
1 string reference to 'LanguageInterfaceContext'
1 service uses LanguageInterfaceContext
File
- src/
EventSubscriber/ LanguageInterfaceContext.php, line 13
Namespace
Drupal\page_manager\EventSubscriberView source
class LanguageInterfaceContext implements EventSubscriberInterface {
/**
* The context repository service.
*
* @var \Drupal\Core\Plugin\Context\ContextRepositoryInterface
*/
protected $contextRepository;
/**
* Creates LanguageInterfaceContext object.
*
* @param \Drupal\Core\Plugin\Context\ContextRepositoryInterface $context_repository
* The context repository service.
*/
public function __construct(ContextRepositoryInterface $context_repository) {
$this->contextRepository = $context_repository;
}
/**
* Add the language_interface context onPageContext event.
*
* @param \Drupal\page_manager\Event\PageManagerContextEvent $event
* The page entity context event.
*/
public function onPageContext(PageManagerContextEvent $event) {
$contexts = $this->contextRepository
->getRuntimeContexts([
'@language.current_language_context:language_interface',
]);
$context = reset($contexts);
$event
->getPage()
->addContext('language_interface', $context);
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[PageManagerEvents::PAGE_CONTEXT][] = 'onPageContext';
return $events;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LanguageInterfaceContext:: |
protected | property | The context repository service. | |
LanguageInterfaceContext:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
LanguageInterfaceContext:: |
public | function | Add the language_interface context onPageContext event. | |
LanguageInterfaceContext:: |
public | function | Creates LanguageInterfaceContext object. |