You are here

public function EventsExampleSubscriber::notifyBatman in Examples for Developers 3.x

Same name and namespace in other branches
  1. 8 events_example/src/EventSubscriber/EventsExampleSubscriber.php \Drupal\events_example\EventSubscriber\EventsExampleSubscriber::notifyBatman()

Let Batman know about any events involving the Joker.

Parameters

\Drupal\events_example\Event\IncidentReportEvent $event: The event object containing the incident report.

File

modules/events_example/src/EventSubscriber/EventsExampleSubscriber.php, line 111

Class

EventsExampleSubscriber
Subscribe to IncidentEvents::NEW_REPORT events and react to new reports.

Namespace

Drupal\events_example\EventSubscriber

Code

public function notifyBatman(IncidentReportEvent $event) {
  if ($event
    ->getType() == 'joker') {
    $this
      ->messenger()
      ->addStatus($this
      ->t('Batman has been alerted. Thank you. This message was set by an event subscriber. See @method()', [
      '@method' => __METHOD__,
    ]));
    $event
      ->stopPropagation();
  }
}