From 11bdc0e1a2fb502b4cf13ad4f32a599f02065e1e 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 997b9b1c..8fbc1b3a 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 @@ class StompHeaderEvent implements StompHeaderEventInterface { return $this->user; } + /** + * {@inheritdoc} + */ + public function getData() { + return $this->data; + } + /** * {@inheritdoc} */ @@ -64,4 +87,11 @@ class StompHeaderEvent implements StompHeaderEventInterface { return $this->headers; } + /** + * {@inheritdoc} + */ + public function getConfiguration() { + return $this->configuration; + } + } diff --git a/src/Event/StompHeaderEventInterface.php b/src/Event/StompHeaderEventInterface.php index 88f85ba1..cdbd455c 100644 --- a/src/Event/StompHeaderEventInterface.php +++ b/src/Event/StompHeaderEventInterface.php @@ -37,4 +37,20 @@ interface StompHeaderEventInterface { */ 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 ab8ddb0f..7c66597d 100644 --- a/src/EventGenerator/EmitEvent.php +++ b/src/EventGenerator/EmitEvent.php @@ -135,7 +135,7 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact $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 03394b3b..2ae4bc8d 100644 --- a/src/EventSubscriber/StompHeaderSubscriber.php +++ b/src/EventSubscriber/StompHeaderSubscriber.php @@ -6,6 +6,7 @@ use Drupal\islandora\Event\StompHeaderEventInterface; 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 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; */ class StompHeaderEventSubscriber implements EventSubscriberInterface { + use StringTranslationTrait; + /** * The JWT auth service. *