class EntityInteractionCollector in Better Statistics 8
Class EntityInteractionCollector.
@package Drupal\better_statistics
Hierarchy
- class \Drupal\better_statistics\EntityInteractionCollector
Expanded class hierarchy of EntityInteractionCollector
1 file declares its use of EntityInteractionCollector
- EntityViewEventSubscriber.php in src/
EventSubscriber/ EntityViewEventSubscriber.php
1 string reference to 'EntityInteractionCollector'
1 service uses EntityInteractionCollector
File
- src/
EntityInteractionCollector.php, line 16
Namespace
Drupal\better_statisticsView source
class EntityInteractionCollector {
/**
* Drupal\sapi\Dispatcher definition.
*
* @var \Drupal\sapi\Dispatcher
*/
protected $sapiDispatcher;
/**
* Drupal\sapi\ActionTypeManager definition.
*
* @var \Drupal\sapi\ActionTypeManager
*/
protected $sapiActionTypeManager;
/**
* EntityInteractionCollector constructor.
*/
public function __construct(Dispatcher $sapiDispatcher, ActionTypeManager $sapiActionTypeManager) {
$this->sapiDispatcher = $sapiDispatcher;
$this->sapiActionTypeManager = $sapiActionTypeManager;
}
/**
* Initiates Drupal\sapi\ActionType plugin and hands it to dispatcher.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* Current actions entity.
* @param string $operation
* Type of operation made on entity.
*/
public function actionTypeTrigger(EntityInterface $entity, AccountProxy $account, $operation) {
$allowed_entities = [
'node',
'user',
'comments',
'taxonomy_term',
];
if (!in_array($entity
->getEntityTypeId(), $allowed_entities)) {
return;
}
try {
/** @var \Drupal\sapi\ActionTypeInterface $action */
$action = $this->sapiActionTypeManager
->createInstance('entity_interaction', [
'entity' => $entity,
'action' => $operation,
'account' => $account,
]);
if (!$action instanceof ActionTypeInterface) {
throw new \Exception('No entity_interaction plugin was found');
}
$this->sapiDispatcher
->dispatch($action);
} catch (\Exception $e) {
watchdog_exception('better_statistics', $e);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityInteractionCollector:: |
protected | property | Drupal\sapi\ActionTypeManager definition. | |
EntityInteractionCollector:: |
protected | property | Drupal\sapi\Dispatcher definition. | |
EntityInteractionCollector:: |
public | function | Initiates Drupal\sapi\ActionType plugin and hands it to dispatcher. | |
EntityInteractionCollector:: |
public | function | EntityInteractionCollector constructor. |