google_analytics_reports-8.x-3.0-rc3/src/Plugin/views/argument_default/GoogleAnalyticsPath.php

src/Plugin/views/argument_default/GoogleAnalyticsPath.php
<?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 getCacheContexts() {
    return ['url'];
  }

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

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc