You are here

GoogleAnalyticsPath.php in Google Analytics Reports 8.3

File

src/Plugin/views/argument_default/GoogleAnalyticsPath.php
View source
<?php

namespace Drupal\google_analytics_reports\Plugin\views\argument_default;

use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * Default argument plugin to use current page path as argument.
 *
 * @ingroup views_argument_default_plugins
 *
 * @ViewsArgumentDefault(
 *   id = "google_analytics_path",
 *   title = @Translation("Current page path (Google Analytics Reports)")
 * )
 */
class GoogleAnalyticsPath extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {

  /**
   * Request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->requestStack = $request_stack;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('request_stack'));
  }

  /**
   * {@inheritdoc}
   */
  public function getArgument() {
    return urldecode($this->requestStack
      ->getCurrentRequest()
      ->getRequestUri());
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheMaxAge() {
    return Cache::PERMANENT;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheContexts() {
    return [
      'url',
    ];
  }

}

Classes

Namesort descending Description
GoogleAnalyticsPath Default argument plugin to use current page path as argument.