-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use destruction events at a later runtime
Fixes #444
- Loading branch information
Showing
6 changed files
with
74 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
modules/next/src/EventSubscriber/EntityActionEventDispatcher.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Drupal\next\EventSubscriber; | ||
|
||
use Drupal\Core\DestructableInterface; | ||
use Drupal\next\Event\EntityActionEvent; | ||
use Drupal\next\Event\EntityEvents; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* Defines an event subscriber for dispatching entity events. | ||
*/ | ||
final class EntityActionEventDispatcher implements DestructableInterface { | ||
|
||
/** | ||
* The events to dispach. | ||
* | ||
* @var \Drupal\next\Event\EntityActionEvent[] | ||
*/ | ||
private array $events = []; | ||
|
||
/** | ||
* EntityActionEventDispatcher constructor. | ||
*/ | ||
public function __construct( | ||
private EventDispatcherInterface $eventDispatcher | ||
) { | ||
} | ||
|
||
/** | ||
* Adds an event to be dispatched at the end of the request. | ||
* | ||
* @param \Drupal\next\Event\EntityActionEvent $event | ||
* The event. | ||
*/ | ||
public function addEvent(EntityActionEvent $event): void { | ||
$this->events[] = $event; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function destruct() { | ||
foreach ($this->events as $event) { | ||
$this->eventDispatcher->dispatch($event, EntityEvents::ENTITY_ACTION); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters