You are here

class EntityInteractionCollector in Better Statistics 8

Class EntityInteractionCollector.

@package Drupal\better_statistics

Hierarchy

Expanded class hierarchy of EntityInteractionCollector

1 file declares its use of EntityInteractionCollector
EntityViewEventSubscriber.php in src/EventSubscriber/EntityViewEventSubscriber.php
1 string reference to 'EntityInteractionCollector'
better_statistics.services.yml in ./better_statistics.services.yml
better_statistics.services.yml
1 service uses EntityInteractionCollector
better_statistics.entity_interaction_collector in ./better_statistics.services.yml
Drupal\better_statistics\EntityInteractionCollector

File

src/EntityInteractionCollector.php, line 16

Namespace

Drupal\better_statistics
View 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

Namesort descending Modifiers Type Description Overrides
EntityInteractionCollector::$sapiActionTypeManager protected property Drupal\sapi\ActionTypeManager definition.
EntityInteractionCollector::$sapiDispatcher protected property Drupal\sapi\Dispatcher definition.
EntityInteractionCollector::actionTypeTrigger public function Initiates Drupal\sapi\ActionType plugin and hands it to dispatcher.
EntityInteractionCollector::__construct public function EntityInteractionCollector constructor.