Skip to content
Snippets Groups Projects
Commit 9fb65d15 authored by Daniel Speicher's avatar Daniel Speicher
Browse files

Resolve #3408174 "Register event before"

parent b39fc6a8
Branches
Tags
1 merge request!12Resolve #3408174 "Register event before"
Pipeline #63229 passed
......@@ -4,11 +4,9 @@ namespace Drupal\eca_push_framework\EventSubscriber;
use Drupal\eca\EcaEvents;
use Drupal\eca\Event\AfterInitialExecutionEvent;
use Drupal\eca\Event\BeforeInitialExecutionEvent;
use Drupal\eca\EventSubscriber\EcaExecutionSubscriberBase;
use Drupal\eca\Plugin\DataType\DataTransferObject;
use Drupal\push_framework\Event\ChannelEventBase;
use Drupal\push_framework\Event\ChannelEventLanguageBase;
use Drupal\push_framework\Event\ChannelPostRender;
use Drupal\push_framework\Event\ChannelPrepareTemplates;
use Drupal\push_framework\Event\ChannelPreRender;
......@@ -18,43 +16,6 @@ use Drupal\push_framework\Event\ChannelPreRender;
*/
class EcaPushFramework extends EcaExecutionSubscriberBase {
/**
* Subscriber method before initial execution.
*
* Adds the event data to the token service.
*
* @param \Drupal\eca\Event\BeforeInitialExecutionEvent $before_event
* The according event.
*
* @throws \Drupal\Core\TypedData\Exception\MissingDataException
*/
public function onBeforeInitialExecution(BeforeInitialExecutionEvent $before_event): void {
$event = $before_event->getEvent();
if ($event instanceof ChannelEventBase) {
$dto = DataTransferObject::create();
$dto->set('channel', $event->getChannelPlugin()->getPluginId());
$dto->set('display_mode', $event->getDisplayMode());
if ($event instanceof ChannelPrepareTemplates) {
$dto->set('subject', $event->getSubject());
$dto->set('body', $event->getBody());
$dto->set('text_format', $event->getTextFormat());
$dto->set('is_html', $event->isHtml());
}
if ($event instanceof ChannelEventLanguageBase) {
$dto->set('language_key', $event->getLanguageKey());
}
if ($event instanceof ChannelPreRender) {
$dto->set('elements', $event->getElements());
}
if ($event instanceof ChannelPostRender) {
$dto->set('output', $event->getOutput());
}
$this->tokenService->addTokenData('push_notification', $dto);
$this->tokenService->addTokenData('push_notification_recipient', $event->getUser());
$this->tokenService->addTokenData('push_notification_entity', $event->getEntity());
}
}
/**
* Subscriber method after initial execution.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment