diff -u b/scheduler.cron.inc b/scheduler.cron.inc --- b/scheduler.cron.inc +++ b/scheduler.cron.inc @@ -10,6 +10,7 @@ use Drupal\Core\Url; use Drupal\node\Entity\Node; +use Drupal\scheduler\SchedulerEvent; use Drupal\scheduler\SchedulerEvents; /** @@ -64,7 +65,8 @@ } // Invoke Scheduler API for modules to react before the node is published. - $dispatcher->dispatch(SchedulerEvents::PRE_PUBLISH, $node); + $event = new SchedulerEvent($node); + $dispatcher->dispatch(SchedulerEvents::PRE_PUBLISH, $event); // If an API call has removed the date $node->set('changed', $publish_on) // would fail, so trap this exception here and give a meaningful message. @@ -120,7 +122,8 @@ } // Invoke scheduler API for modules to react after the node is published. - $dispatcher->dispatch(SchedulerEvents::PUBLISH, $node); + $event = new SchedulerEvent($node); + $dispatcher->dispatch(SchedulerEvents::PUBLISH, $event); $result = TRUE; } @@ -182,7 +185,8 @@ } // Invoke scheduler API for modules to react before the node is unpublished. - $dispatcher->dispatch(SchedulerEvents::PRE_UNPUBLISH, $node); + $event = new SchedulerEvent($node); + $dispatcher->dispatch(SchedulerEvents::PRE_UNPUBLISH, $event); // If an API call has removed the date $node->set('changed', $unpublish_on) // would fail, so trap this exception here and give a meaningful message. @@ -235,7 +239,8 @@ } // Invoke scheduler API for modules to react after the node is unpublished. - $dispatcher->dispatch(SchedulerEvents::UNPUBLISH, $node); + $event = new SchedulerEvent($node); + $dispatcher->dispatch(SchedulerEvents::UNPUBLISH, $event); $result = TRUE; } diff -u b/scheduler.module b/scheduler.module --- b/scheduler.module +++ b/scheduler.module @@ -14,6 +14,7 @@ use Drupal\Core\Url; use Drupal\node\NodeInterface; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\scheduler\SchedulerEvent; use Drupal\scheduler\SchedulerEvents; // @todo Move constants into a class, so we do not pollute the global space, @@ -317,8 +318,6 @@ * Implements hook_ENTITY_TYPE_presave() for node entities. */ function scheduler_node_presave(EntityInterface $node) { - /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */ - $dispatcher = \Drupal::service('event_dispatcher'); $entity = $node->type->entity; // If the node type is not enabled for Scheduler then do nothing. if (!$entity->getThirdPartySetting('scheduler', 'publish_enable', FALSE)) { @@ -340,7 +339,8 @@ $node->publish_on->value = NULL; $node->setPublished(TRUE); // Allow modules to react to immediate publishing. - \Drupal::service('event_dispatcher')->dispatch(SchedulerEvents::PUBLISH_IMMEDIATELY, $node); + $event = new SchedulerEvent($node); + \Drupal::service('event_dispatcher')->dispatch(SchedulerEvents::PUBLISH_IMMEDIATELY, $event); } else { // Ensure the node is unpublished as it will be published by cron later.