You are here

public function SchedulerManager::dispatch in Scheduler 8

Same name and namespace in other branches
  1. 2.x src/SchedulerManager.php \Drupal\scheduler\SchedulerManager::dispatch()

Dispatch a Scheduler event.

All Scheduler events should be dispatched through this common function.

Drupal 8.8 and 8.9 use Symfony 3.4 and from Drupal 9.0 the Symfony version is 4.4. Starting with Symfony 4.3 the signature of the event dispatcher function has the parameters swapped round, the event object is first, followed by the event name string. At 9.0 the existing signature has to be used but from 9.1 the parameters must be switched.

Parameters

\Drupal\Component\EventDispatcher\Event $event: The event object.

string $event_name: The text name for the event.

See also

https://www.drupal.org/project/scheduler/issues/3166688

2 calls to SchedulerManager::dispatch()
SchedulerManager::publish in src/SchedulerManager.php
Publish scheduled nodes.
SchedulerManager::unpublish in src/SchedulerManager.php
Unpublish scheduled nodes.

File

src/SchedulerManager.php, line 107

Class

SchedulerManager
Defines a scheduler manager.

Namespace

Drupal\scheduler

Code

public function dispatch(Event $event, string $event_name) {

  // \Symfony\Component\HttpKernel\Kernel::VERSION will give the symfony
  // version. However, testing this does not give the required outcome, we
  // need to test the Drupal core version.
  // @todo Remove the check when Core 9.1 is the lowest supported version.
  if (version_compare(\Drupal::VERSION, '9.1', '>=')) {

    // The new way, with $event first.
    $this->eventDispatcher
      ->dispatch($event, $event_name);
  }
  else {

    // Replicate the existing dispatch signature.
    $this->eventDispatcher
      ->dispatch($event_name, $event);
  }
}