- Issue created by @purencool
- 🇦🇺Australia purencool
Hey the following need be removed or commented out as it's throwing a 500. What is they do?
// Instantiate our event. // $event = new TaskWorkEvent($task, $filtered_comment, $work_done, $uid); // Dispatch the event. //static::getContainer()->eventDispatcher->dispatch(TaskWorkEvent::WORKED, $event);
- 🇨🇦Canada jeremylichtman
Can you please check your Drupal log to see what the error is? I won't have a chance to test this until probably next week...
These a) actually add the work record that the user entered in the form, and b) dispatch an event that other modules could use.
- 🇨🇦Canada jeremylichtman
This should work:
$this->eventDispatcher->dispatch->(TaskWorkEvent::WORKED, $event);
- 🇦🇺Australia purencool
Changed the code to the following
// Instantiate our event. $event = new TaskWorkEvent($task, $filtered_comment, $work_done, $uid); // Dispatch the event. $this->eventDispatcher->dispatch(TaskWorkEvent::WORKED, $event);
Got the following error
TypeError: Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch(): Argument #1 ($event) must be of type object, string given, called in /var/www/html/web/modules/contrib/burndown/src/Controller/TaskController.php on line 233 in Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (line 89 of /var/www/html/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php).
- 🇦🇺Australia purencool
This worked.
// Instantiate our event. $event = new TaskWorkEvent($task, $filtered_comment, $work_done, $uid); // Dispatch the event. $this->eventDispatcher->dispatch( $event,TaskWorkEvent::WORKED);
- 🇦🇺Australia purencool
Interesting the class has the following logic.
class TaskWorkEvent extends Event { const WORKED = 'burndown_event_task_work'; /** * The task. * * @var Drupal\Core\Entity\EntityInterface */ public $task; /** * The comment. * * @var string */ public $comment; /** * The amount of work done. * * @var string */ public $workDone; /** * The user who did the work. * * @var int */ public $uid; /** * Constructs the object. * * @param Drupal\Core\Entity\EntityInterface $task * The newly created task. * @param string $comment * The comment. * @param string $workDone * The mount of work done. * @param int $uid * The id of the user who did the work. * * @todo Provide more detailed/explanatory comments on parameters. */ public function __construct(EntityInterface $task, $comment, $workDone, $uid) { // $created, $uid, $this->task = $task; $this->comment = $comment; $this->workDone = $workDone; $this->uid = $uid; } }
- 🇨🇦Canada jeremylichtman
Ah. There's other event dispatches in the controller.
I've pushed the fix (with your reordering) to dev.