You are here

public function FlagEvents::onFlag in Flag 8.4

React to flagging event.

Parameters

\Drupal\flag\Event\FlaggingEvent $event: The flagging event.

File

tests/modules/flag_event_test/src/EventSubscriber/FlagEvents.php, line 59

Class

FlagEvents
Test flag events subscriber.

Namespace

Drupal\flag_event_test\EventSubscriber

Code

public function onFlag(FlaggingEvent $event) {
  if ($flag_id = $this->state
    ->get('flag_test.react_flag_event', FALSE)) {
    $flag = $this->flagService
      ->getFlagById($flag_id);
    assert('$event->getFlagging()->getFlag()->id() !== $flag->id()', 'Should not test the flagging event with the same flag that is being flagged.');
    $this->state
      ->set('flag_test.is_flagged', $flag
      ->isFlagged($event
      ->getFlagging()
      ->getFlaggable(), $event
      ->getFlagging()
      ->getOwner()));
  }
}