You are here

class CollectEvent in Googalytics - Google Analytics 8

Class CollectEvent.

Hierarchy

  • class \Drupal\ga\Event\CollectEvent extends \Symfony\Component\EventDispatcher\Event

Expanded class hierarchy of CollectEvent

3 files declare their use of CollectEvent
AnalyticsSubscriber.php in modules/ga_tokens/src/EventSubscriber/AnalyticsSubscriber.php
DefaultCommandSubscriber.php in src/EventSubscriber/DefaultCommandSubscriber.php
ga.module in ./ga.module
Contains ga.module.

File

src/Event/CollectEvent.php, line 11

Namespace

Drupal\ga\Event
View source
class CollectEvent extends Event {

  /**
   * The registered analytics commands.
   *
   * @var \Drupal\ga\AnalyticsCommand\DrupalSettingCommandsInterface[]
   */
  protected $commands;

  /**
   * CollectEvent constructor.
   */
  public function __construct() {
    $this->commands = [];
  }

  /**
   * Add a command.
   *
   * @param \Drupal\ga\AnalyticsCommand\DrupalSettingCommandsInterface $command
   *   An analytics command.
   */
  public function addCommand(DrupalSettingCommandsInterface $command) {
    $this->commands[] = $command;
  }

  /**
   * Format the commands for use in drupalSettings.
   *
   * @return array
   *   An array of commands for use in drupalSettings.
   */
  public function getDrupalSettingCommands() {
    usort($this->commands, function (DrupalSettingCommandsInterface $a, DrupalSettingCommandsInterface $b) {
      return $b
        ->getPriority() - $a
        ->getPriority();
    });
    return array_reduce($this->commands, function ($carry, DrupalSettingCommandsInterface $item) {
      return array_merge($carry, $item
        ->getSettingCommands());
    }, []);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CollectEvent::$commands protected property The registered analytics commands.
CollectEvent::addCommand public function Add a command.
CollectEvent::getDrupalSettingCommands public function Format the commands for use in drupalSettings.
CollectEvent::__construct public function CollectEvent constructor.