function Connection::dispatchEvent

Same name in other branches
  1. 10 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::dispatchEvent()

Dispatches a database API event via the container dispatcher.

Parameters

\Drupal\Core\Database\Event\DatabaseEvent $event: The database event.

string|null $eventName: (Optional) the name of the event to dispatch.

Return value

\Drupal\Core\Database\Event\DatabaseEvent The database event.

Throws

\Drupal\Core\Database\Exception\EventException If the container is not initialized.

File

core/lib/Drupal/Core/Database/Connection.php, line 1525

Class

Connection
Base Database API class.

Namespace

Drupal\Core\Database

Code

public function dispatchEvent(DatabaseEvent $event, ?string $eventName = NULL) : DatabaseEvent {
    if (\Drupal::hasService('event_dispatcher')) {
        return \Drupal::service('event_dispatcher')->dispatch($event, $eventName);
    }
    throw new EventException('The event dispatcher service is not available. Database API events can only be fired if the container is initialized');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.