You are here

public function EntityViewEventSubscriber::onEventView in Better Statistics 8

Triggering method for entity view routes.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event: Event that called action.

File

src/EventSubscriber/EntityViewEventSubscriber.php, line 73

Class

EntityViewEventSubscriber
Class EntityViewEventSubscriber.

Namespace

Drupal\better_statistics\EventSubscriber

Code

public function onEventView(GetResponseForControllerResultEvent $event) {
  try {
    if (preg_match('/entity\\.([\\w]+)\\.canonical/', $this->currentRouteMatch
      ->getRouteName(), $matches)) {

      /** @var \Drupal\Core\Entity\EntityInterface $entity */
      $entity = $this->currentRouteMatch
        ->getParameter($matches[1]);

      // Pass the interaction to the collector.
      $this->entityInteractionCollector
        ->actionTypeTrigger($entity, $this->currentUser, self::ACTION_VIEW);
    }
  } catch (\Exception $e) {
    watchdog_exception('better_statistics', $e);
  }
}