From 2f06c987609dfb003d17bbcc42e0bdb47219b4e2 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 14 Jun 2021 16:04:59 -0300 Subject: [PATCH] More context. --- src/Event/StompHeaderEvent.php | 32 ++++++++++++++++++- src/Event/StompHeaderEventInterface.php | 16 ++++++++++ src/EventGenerator/EmitEvent.php | 2 +- src/EventSubscriber/StompHeaderSubscriber.php | 3 ++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/Event/StompHeaderEvent.php b/src/Event/StompHeaderEvent.php index 997b9b1c3..8fbc1b3aa 100644 --- a/src/Event/StompHeaderEvent.php +++ b/src/Event/StompHeaderEvent.php @@ -27,6 +27,20 @@ class StompHeaderEvent implements StompHeaderEventInterface { */ protected $user; + /** + * An array of data to be sent with the STOMP request, for context. + * + * @var array + */ + protected $data; + + /** + * An array of configuration used to generate $data, for context. + * + * @var array + */ + protected $configuration; + /** * The set of headers. * @@ -37,9 +51,11 @@ class StompHeaderEvent implements StompHeaderEventInterface { /** * Constructor. */ - public function __construct(EntityInterface $entity, AccountInterface $user) { + public function __construct(EntityInterface $entity, AccountInterface $user, array $data, array $configuration) { $this->entity = $entity; $this->user = $user; + $this->data = $data; + $this->configuration = $configuration; $this->headers = new ParameterBag(); } @@ -57,6 +73,13 @@ public function getUser() { return $this->user; } + /** + * {@inheritdoc} + */ + public function getData() { + return $this->data; + } + /** * {@inheritdoc} */ @@ -64,4 +87,11 @@ public function getHeaders() { return $this->headers; } + /** + * {@inheritdoc} + */ + public function getConfiguration() { + return $this->configuration; + } + } diff --git a/src/Event/StompHeaderEventInterface.php b/src/Event/StompHeaderEventInterface.php index 88f85ba15..cdbd455c1 100644 --- a/src/Event/StompHeaderEventInterface.php +++ b/src/Event/StompHeaderEventInterface.php @@ -37,4 +37,20 @@ public function getEntity(); */ public function getUser(); + /** + * Fetch the data to be sent in the body of the request. + * + * @return array + * The array of data. + */ + public function getData(); + + /** + * Fetch the configuration of the action, for context. + * + * @return array + * The array of configuration for the upstream action. + */ + public function getConfiguration(); + } diff --git a/src/EventGenerator/EmitEvent.php b/src/EventGenerator/EmitEvent.php index 44ba867e9..4f71bbb76 100644 --- a/src/EventGenerator/EmitEvent.php +++ b/src/EventGenerator/EmitEvent.php @@ -120,7 +120,7 @@ public function execute($entity = NULL) { $event = $this->eventDispatcher->dispatch( StompHeaderEvent::EVENT_NAME, - new StompHeaderEvent($entity, $user) + new StompHeaderEvent($entity, $user, $data, $this->getConfiguration()) ); $message = new Message( diff --git a/src/EventSubscriber/StompHeaderSubscriber.php b/src/EventSubscriber/StompHeaderSubscriber.php index 03394b3b9..2ae4bc8d6 100644 --- a/src/EventSubscriber/StompHeaderSubscriber.php +++ b/src/EventSubscriber/StompHeaderSubscriber.php @@ -6,6 +6,7 @@ use Drupal\jwt\Authentication\Provider\JwtAuth; use Drupal\Core\Messenger\MessengerInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -15,6 +16,8 @@ */ class StompHeaderEventSubscriber implements EventSubscriberInterface { + use StringTranslationTrait; + /** * The JWT auth service. *