class FlagForListSubscriber in Flag Lists 8
Same name and namespace in other branches
- 4.0.x src/EventSubscriber/FlagForListSubscriber.php \Drupal\flag_lists\EventSubscriber\FlagForListSubscriber
Class FlagForListSubscriber.
Hierarchy
- class \Drupal\flag_lists\EventSubscriber\FlagForListSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses MessengerTrait
Expanded class hierarchy of FlagForListSubscriber
1 string reference to 'FlagForListSubscriber'
1 service uses FlagForListSubscriber
File
- src/
EventSubscriber/ FlagForListSubscriber.php, line 13
Namespace
Drupal\flag_lists\EventSubscriberView source
class FlagForListSubscriber implements EventSubscriberInterface {
use MessengerTrait;
/**
* Constructs a new FlagForListSubscriber object.
*/
public function __construct() {
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[FlagEvents::ENTITY_FLAGGED][] = [
'flagListsEntityFlagged',
100,
];
$events[FlagEvents::ENTITY_UNFLAGGED][] = [
'flagListsEntityUnflagged',
100,
];
return $events;
}
/**
* This is called whenever the flag.entity_flagged event is dispatched.
*
* @param Symfony\Component\EventDispatcher\Event $flag_event
* The response event.
*/
public function flagListsEntityFlagged(Event $flag_event) {
$flagId = $flag_event
->getFlagging()
->getFlagId();
foreach (\Drupal::service('flaglists')
->getAllFlagForList() as $collection) {
if ($collection
->getBaseFlag() == $flagId) {
$this
->messenger()
->addMessage(t('Entity added to the %flaglist list.', [
'%flaglist' => $flagId,
]));
}
}
}
/**
* This is called whenever the flag.entity_unflagged event is dispatched.
*
* @param Symfony\Component\EventDispatcher\Event $flag_events
* The response events.
*/
public function flagListsEntityUnflagged(Event $flag_events) {
foreach ($flag_events
->getFlaggings() as $flagging) {
$flagId = $flagging
->getFlagId();
foreach (\Drupal::service('flaglists')
->getAllFlagForList() as $collection) {
if ($collection
->getBaseFlag() == $flagId) {
$this
->messenger()
->addMessage(t('Entity removed from the %flaglist list.', [
'%flaglist' => $flagId,
]));
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FlagForListSubscriber:: |
public | function | This is called whenever the flag.entity_flagged event is dispatched. | |
FlagForListSubscriber:: |
public | function | This is called whenever the flag.entity_unflagged event is dispatched. | |
FlagForListSubscriber:: |
public static | function | ||
FlagForListSubscriber:: |
public | function | Constructs a new FlagForListSubscriber object. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. |