You are here

public function FlagEvents::onUnflag in Flag 8.4

React to unflagging event.

Parameters

\Drupal\flag\Event\UnflaggingEvent $event: The unflagging event.

File

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

Class

FlagEvents
Test flag events subscriber.

Namespace

Drupal\flag_event_test\EventSubscriber

Code

public function onUnflag(UnflaggingEvent $event) {
  if ($flag_id = $this->state
    ->get('flag_test.react_unflag_event', FALSE)) {
    $flag = $this->flagService
      ->getFlagById($flag_id);
    foreach ($event
      ->getFlaggings() as $flagging) {
      assert('$flagging->getFlag()->id() != $flag->id()', 'Should not test the unflagging event with the same flag that is being unflagged.');
      $this->state
        ->set('flag_test.is_unflagged', $flag
        ->isFlagged($flagging
        ->getFlaggable(), $flagging
        ->getOwner()));
    }
  }
}