Commit c2c4c320 authored by Julian Pustkuchen's avatar Julian Pustkuchen
Browse files

Issue #3215789 by sorabh.v6, andyg5000, Anybody: Allow developers to alter event data

parent 2785d65e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
services:
  facebook_pixel.facebook_event:
    class: Drupal\facebook_pixel\FacebookEvent
    arguments: ['@tempstore.private', '@session_manager']
    arguments: ['@tempstore.private', '@session_manager', '@module_handler']
+14 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\facebook_pixel;

use Drupal\Core\Session\SessionManager;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\Core\Extension\ModuleHandlerInterface;

/**
 * Helper methods for facebook_pixel module.
@@ -33,6 +34,13 @@ class FacebookEvent implements FacebookEventInterface {
   */
  protected $sessionManager;

  /**
   * The module handler.
   *
   * @var Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * FacebookEvent constructor.
   *
@@ -40,10 +48,13 @@ class FacebookEvent implements FacebookEventInterface {
   *   The temp store factory service.
   * @param \Drupal\Core\Session\SessionManager $session
   *   The session manager service.
   * @param Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
   *   The module handler.
   */
  public function __construct(PrivateTempStoreFactory $temp_store_factory, SessionManager $session) {
  public function __construct(PrivateTempStoreFactory $temp_store_factory, SessionManager $session, ModuleHandlerInterface $moduleHandler) {
    $this->privateTempStore = $temp_store_factory->get('user');
    $this->sessionManager = $session;
    $this->moduleHandler = $moduleHandler;
  }

  /**
@@ -59,6 +70,8 @@ class FacebookEvent implements FacebookEventInterface {
   * @throws \Drupal\Core\TempStore\TempStoreException
   */
  public function addEvent($event, $data = '', $start_session = FALSE) {
    // Allow to alter the event data using a hook:
    $this->moduleHandler->invokeAll('facebook_pixel_event_data_alter', [&$data, $event]);
    // Determine if we should use session or static storage.
    if ((!empty($this->sessionManager) && $this->sessionManager->isStarted()) || $start_session) {
      $this->addSessionEvent($event, $data);