-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use destruction events at a later runtime
- Loading branch information
Showing
3 changed files
with
44 additions
and
13 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
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
<?php | ||
|
||
namespace Drupal\next\EventSubscriber; | ||
|
||
use Drupal\Core\DestructableInterface; | ||
use Drupal\next\Event\EntityActionEvent; | ||
use Drupal\next\Event\EntityEvents; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; | ||
|
||
final class EntityActionEventDispatcher implements DestructableInterface { | ||
|
||
/** | ||
* @var \Drupal\next\Event\EntityActionEvent[] | ||
*/ | ||
private array $events = []; | ||
|
||
public function __construct( | ||
private EventDispatcherInterface $eventDispatcher | ||
) { | ||
} | ||
|
||
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); | ||
} | ||
} | ||
|
||
} |