class FlagSearchApiSubscriber in Flag Search API 8
Class FlagSearchApiSubscriber.
Hierarchy
- class \Drupal\flag_search_api\EventSubscriber\FlagSearchApiSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of FlagSearchApiSubscriber
1 string reference to 'FlagSearchApiSubscriber'
1 service uses FlagSearchApiSubscriber
File
- src/
EventSubscriber/ FlagSearchApiSubscriber.php, line 13
Namespace
Drupal\flag_search_api\EventSubscriberView source
class FlagSearchApiSubscriber implements EventSubscriberInterface {
/**
* Drupal\Core\Entity\EntityTypeManagerInterface definition.
*
* @var \Drupal\flag_search_api\FlagSearchApiReindexService
*/
protected $flagSearchApiReindex;
/**
* Constructs a new FlagSearchApiSubscriber object.
*
* @param \Drupal\flag_search_api\FlagSearchApiReindexService $flag_search_api_reindex_service
* FlagSearchApiReindexService.
*/
public function __construct(FlagSearchApiReindexService $flag_search_api_reindex_service) {
$this->flagSearchApiReindex = $flag_search_api_reindex_service;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events['flag.entity_flagged'] = [
'flagEntityFlagged',
];
$events['flag.entity_unflagged'] = [
'flagEntityUnflagged',
];
return $events;
}
/**
* Method is called whenever the flag.entity_flagged event is dispatched.
*
* @param \Drupal\flag\Event\FlaggingEvent $event
* Event.
*/
public function flagEntityFlagged(FlaggingEvent $event) {
$this->flagSearchApiReindex
->reindexItem($event
->getFlagging());
}
/**
* Method is called whenever the flag.entity_unflagged event is dispatched.
*
* @param \Drupal\flag\Event\UnflaggingEvent $event
* Event.
*/
public function flagEntityUnflagged(UnflaggingEvent $event) {
$flaggings = $event
->getFlaggings();
/** @var \Drupal\flag\FlaggingInterface $flagging */
foreach ($flaggings as $flagging) {
$this->flagSearchApiReindex
->reindexItem($flagging);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FlagSearchApiSubscriber:: |
protected | property | Drupal\Core\Entity\EntityTypeManagerInterface definition. | |
FlagSearchApiSubscriber:: |
public | function | Method is called whenever the flag.entity_flagged event is dispatched. | |
FlagSearchApiSubscriber:: |
public | function | Method is called whenever the flag.entity_unflagged event is dispatched. | |
FlagSearchApiSubscriber:: |
public static | function | ||
FlagSearchApiSubscriber:: |
public | function | Constructs a new FlagSearchApiSubscriber object. |