final class PreprocessEventService in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 modules/preprocess_event_dispatcher/src/Service/PreprocessEventService.php \Drupal\preprocess_event_dispatcher\Service\PreprocessEventService
Class PreprocessEventService.
Hierarchy
- class \Drupal\preprocess_event_dispatcher\Service\PreprocessEventService implements PreprocessEventServiceInterface
Expanded class hierarchy of PreprocessEventService
2 files declare their use of PreprocessEventService
- EntityEventTest.php in modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ EntityEventTest.php - OtherEventTest.php in modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ OtherEventTest.php
1 string reference to 'PreprocessEventService'
- preprocess_event_dispatcher.services.yml in modules/
preprocess_event_dispatcher/ preprocess_event_dispatcher.services.yml - modules/preprocess_event_dispatcher/preprocess_event_dispatcher.services.yml
1 service uses PreprocessEventService
- preprocess_event.service in modules/
preprocess_event_dispatcher/ preprocess_event_dispatcher.services.yml - Drupal\preprocess_event_dispatcher\Service\PreprocessEventService
File
- modules/
preprocess_event_dispatcher/ src/ Service/ PreprocessEventService.php, line 11
Namespace
Drupal\preprocess_event_dispatcher\ServiceView source
final class PreprocessEventService implements PreprocessEventServiceInterface {
/**
* Event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
private $dispatcher;
/**
* Factory mapper.
*
* @var PreprocessEventFactoryMapper
*/
private $mapper;
/**
* PreprocessEventService constructor.
*
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
* Event dispatcher.
* @param PreprocessEventFactoryMapper $mapper
* Factory mapper.
*/
public function __construct(EventDispatcherInterface $dispatcher, PreprocessEventFactoryMapper $mapper) {
$this->dispatcher = $dispatcher;
$this->mapper = $mapper;
}
/**
* {@inheritdoc}
*/
public function createAndDispatchKnownEvents(string $hook, array &$variables) : void {
$factory = $this->mapper
->getFactory($hook);
if ($factory === NULL) {
return;
}
$event = $factory
->createEvent($variables);
$this->dispatcher
->dispatch($event::name(), $event);
if ($event instanceof PreprocessEntityEventInterface) {
$this
->dispatchEntitySpecificEvents($event);
}
}
/**
* Dispatch the entity events.
*
* @param \Drupal\preprocess_event_dispatcher\Event\PreprocessEntityEventInterface $event
* The event to dispatch.
*/
private function dispatchEntitySpecificEvents(PreprocessEntityEventInterface $event) : void {
$variables = $event
->getVariables();
$withBundle = $event::name($variables
->getEntityBundle());
$this->dispatcher
->dispatch($withBundle, $event);
$withViewMode = $event::name($variables
->getEntityBundle(), $variables
->getViewMode());
$this->dispatcher
->dispatch($withViewMode, $event);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PreprocessEventService:: |
private | property | Event dispatcher. | |
PreprocessEventService:: |
private | property | Factory mapper. | |
PreprocessEventService:: |
public | function |
Create and dispatch the event. Overrides PreprocessEventServiceInterface:: |
|
PreprocessEventService:: |
private | function | Dispatch the entity events. | |
PreprocessEventService:: |
public | function | PreprocessEventService constructor. |