Last active
July 17, 2018 15:34
-
-
Save miloskroulik/ce690a206e31fa750c9a9956dd466f52 to your computer and use it in GitHub Desktop.
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
From c23be7ed86a3a04e3cb85aaef91619ebf115421a Mon Sep 17 00:00:00 2001 | |
From: =?UTF-8?q?Milo=C5=A1=20Kroul=C3=ADk?= <milos.kroulik@proofreason.com> | |
Date: Tue, 17 Jul 2018 17:30:19 +0200 | |
Subject: [PATCH] Fix problem with event dispatcher Fix event dispatcher, so | |
we're sending the right data | |
--- | |
src/Controller/H5PAJAX.php | 6 +++--- | |
src/Event/FinishedEvent.php | 25 ++++++++++--------------- | |
2 files changed, 13 insertions(+), 18 deletions(-) | |
diff --git a/src/Controller/H5PAJAX.php b/src/Controller/H5PAJAX.php | |
index 4e8e215..29065ee 100644 | |
--- a/src/Controller/H5PAJAX.php | |
+++ b/src/Controller/H5PAJAX.php | |
@@ -8,7 +8,7 @@ use Drupal\Core\Database\Connection; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
use Drupal\h5p\H5PDrupal\H5PDrupal; | |
-use Symfony\Component\EventDispatcher\EventDispatcher; | |
+use Symfony\Component\EventDispatcher\EventDispatcherInterface; | |
use Drupal\h5p\Event\FinishedEvent; | |
class H5PAJAX extends ControllerBase { | |
@@ -20,7 +20,7 @@ class H5PAJAX extends ControllerBase { | |
/** | |
* DBExample constructor. | |
*/ | |
- public function __construct(Connection $database, EventDispatcher $event_dispatcher) { | |
+ public function __construct(Connection $database, EventDispatcherInterface $event_dispatcher) { | |
$this->database = $database; | |
$this->event_dispatcher = $event_dispatcher; | |
} | |
@@ -94,7 +94,7 @@ class H5PAJAX extends ControllerBase { | |
->fields($fields) | |
->execute(); | |
- $this->event_dispatcher->dispatch(FinishedEvent::FINISHED_EVENT, new FinishedEvent($this->database)); | |
+ $this->event_dispatcher->dispatch(FinishedEvent::FINISHED_EVENT, new FinishedEvent($fields)); | |
return new JsonResponse(['success' => TRUE]); | |
} | |
diff --git a/src/Event/FinishedEvent.php b/src/Event/FinishedEvent.php | |
index 6383304..c0c4b53 100644 | |
--- a/src/Event/FinishedEvent.php | |
+++ b/src/Event/FinishedEvent.php | |
@@ -3,8 +3,6 @@ | |
namespace Drupal\h5p\Event; | |
use Symfony\Component\EventDispatcher\Event; | |
-use Drupal\Core\Entity\EntityInterface; | |
-use Drupal\Core\Database\Connection; | |
/** | |
* Wraps a node insertion demo event for event listeners. | |
@@ -14,28 +12,25 @@ class FinishedEvent extends Event { | |
const FINISHED_EVENT = 'h5p.finished'; | |
/** | |
- * Node entity. | |
- * | |
- * @var \Drupal\Core\Entity\EntityInterface | |
+ * @var array | |
*/ | |
- protected $database; | |
+ protected $quizData; | |
/** | |
- * Constructs a node insertion demo event object. | |
+ * Constructs a FinishedEvent object. | |
* | |
- * @param \Drupal\Core\Database\Connection $database | |
+ * @param array $quizData | |
* Database connection service. | |
*/ | |
- public function __construct(Connection $database) { | |
- $this->database = $database; | |
+ public function __construct(array $quizData) { | |
+ $this->quizData = $quizData; | |
} | |
/** | |
- * Get the inserted entity. | |
- * | |
- * @return \Drupal\Core\Database\Connection | |
+ * @return array | |
+ * Quiz data. | |
*/ | |
- public function getDatabase() { | |
- return $this->database; | |
+ public function getQuizFields() { | |
+ return $this->quizData; | |
} | |
} | |
\ No newline at end of file | |
-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://x-team.com/blog/creating-and-subscribing-to-events/