From d1eae00b48b1915dfc7207fba565325205a6924e Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen.haas@lakedrops.com>
Date: Thu, 14 Dec 2023 09:13:41 +0100
Subject: [PATCH] Issue #3408174 by danielspeicher: Register event before
 execution

---
 .../eca/src/Plugin/ECA/Event/ChannelEvent.php | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/modules/eca/src/Plugin/ECA/Event/ChannelEvent.php b/modules/eca/src/Plugin/ECA/Event/ChannelEvent.php
index 56ec824..624b807 100644
--- a/modules/eca/src/Plugin/ECA/Event/ChannelEvent.php
+++ b/modules/eca/src/Plugin/ECA/Event/ChannelEvent.php
@@ -52,19 +52,18 @@ class ChannelEvent extends EventBase {
   /**
    * {@inheritdoc}
    */
-  protected function buildEventData(): array {
+  public function getData(string $key): mixed {
     $event = $this->getEvent();
-    $data = [];
 
-    if ($event instanceof ChannelEventBase) {
-      $data['push_notification'] = [
+    if ($key === 'push_notification' && $event instanceof ChannelEventBase) {
+      $data = [
         'channel' => $event->getChannelPlugin()->getPluginId(),
         'recipient' => $event->getUser(),
         'entity' => $event->getEntity(),
         'display_mode' => $event->getDisplayMode(),
       ];
       if ($event instanceof ChannelPrepareTemplates) {
-        $data['push_notification'] += [
+        $data += [
           'subject' => $event->getSubject(),
           'body' => $event->getBody(),
           'text_format' => $event->getTextFormat(),
@@ -72,24 +71,24 @@ class ChannelEvent extends EventBase {
         ];
       }
       if ($event instanceof ChannelEventLanguageBase) {
-        $data['push_notification'] += [
+        $data += [
           'language_key' => $event->getLanguageKey(),
         ];
       }
       if ($event instanceof ChannelPreRender) {
-        $data['push_notification'] += [
+        $data += [
           'elements' => $event->getElements(),
         ];
       }
       if ($event instanceof ChannelPostRender) {
-        $data['push_notification'] += [
+        $data += [
           'output' => $event->getOutput(),
         ];
       }
+      return $data;
     }
 
-    $data += parent::buildEventData();
-    return $data;
+    return parent::getData($key);
   }
 
 }
-- 
GitLab