Commit 5262ecf4 authored by Ivica Puljic's avatar Ivica Puljic Committed by Ivica Puljic
Browse files

Issue #3294077 by pivica, Harsh panchal: Phpcs Drupal coding standard issue

parent dca16242
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ class SettingsForm extends ConfigFormBase {
  /**
   * The umami analytics local javascript cache manager.
   *
   * @var JavascriptLocalCache
   * @var \Drupal\umami_analytics\JavascriptLocalCache
   */
  protected $uaJavascript;

@@ -25,8 +25,6 @@ class SettingsForm extends ConfigFormBase {
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   The current user.
   * @param \Drupal\umami_analytics\JavascriptLocalCache $umami_analytics_javascript
   *   The JS Local Cache service.
   */
@@ -159,7 +157,9 @@ class SettingsForm extends ConfigFormBase {
      '#title' => $this->t('Pages'),
      '#title_display' => 'invisible',
      '#default_value' => !empty($visibility_request_path_pages) ? $visibility_request_path_pages : '',
      '#description' => $this->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", ['%blog' => '/blog', '%blog-wildcard' => '/blog/*', '%front' => '<front>']),
      '#description' => $this->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.",
        ['%blog' => '/blog', '%blog-wildcard' => '/blog/*', '%front' => '<front>']
      ),
      '#rows' => 10,
    ];

@@ -245,6 +245,7 @@ class SettingsForm extends ConfigFormBase {
    // Clear obsolete local cache if cache has been disabled.
    if ($form_state->isValueEmpty('local_cache') && $form['advanced']['local_cache']['#default_value']) {
      $this->gaJavascript->clearJsCache();
      return;
    }
  }

+13 −1
Original line number Diff line number Diff line
@@ -13,21 +13,29 @@ use Drupal\path_alias\AliasManagerInterface;
class VisiblityTracker {

  /**
   * The alias manager.
   *
   * @var \Drupal\path_alias\AliasManagerInterface
   */
  private $aliasManager;

  /**
   * The path matcher.
   *
   * @var \Drupal\Core\Path\PathMatcherInterface
   */
  private $pathMatcher;

  /**
   * Umami analytics settings.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  private $config;

  /**
   * The current path of current request.
   *
   * @var \Drupal\Core\Path\CurrentPathStack
   */
  private $currentPath;
@@ -41,6 +49,8 @@ class VisiblityTracker {
   *   The alias manager service.
   * @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
   *   The path matcher service.
   * @param \Drupal\Core\Path\CurrentPathStack $current_path
   *   The current path.
   */
  public function __construct(ConfigFactoryInterface $config_factory, AliasManagerInterface $alias_manager, PathMatcherInterface $path_matcher, CurrentPathStack $current_path) {
    $this->config = $config_factory->get('umami_analytics.settings');
@@ -78,7 +88,8 @@ class VisiblityTracker {
      }
    }
    else {
      // No role is selected for tracking, therefore all roles should be tracked.
      // No role is selected for tracking, therefore all roles should be
      // tracked.
      $enabled = TRUE;
    }

@@ -125,4 +136,5 @@ class VisiblityTracker {
    }
    return $page_match;
  }

}
+17 −0
Original line number Diff line number Diff line
@@ -10,33 +10,49 @@ use Drupal\Core\State\StateInterface;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;

/**
 * Javascript local cache helper service class.
 */
class JavascriptLocalCache {

  /**
   * The file system service.
   *
   * @var \Drupal\Core\File\FileSystem
   */
  protected $fileSystem;

  /**
   * The configuration factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * A logger channel instance for umami_analytics.
   *
   * @var \Drupal\Core\Logger\LoggerChannelInterface
   */
  protected $logger;

  /**
   * The client for sending HTTP requests.
   *
   * @var \GuzzleHttp\ClientInterface
   */
  protected $httpClient;

  /**
   * The state system.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * The construct.
   */
  public function __construct(ClientInterface $http_client, FileSystemInterface $file_system, ConfigFactoryInterface $config_factory, LoggerChannelFactoryInterface $logger_factory, StateInterface $state) {
    $this->httpClient = $http_client;
    $this->fileSystem = $file_system;
@@ -44,6 +60,7 @@ class JavascriptLocalCache {
    $this->state = $state;
    $this->logger = $logger_factory->get('umami_analytics');
  }

  /**
   * Download/Synchronize/Cache tracking code file locally.
   *
+1 −2
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@
 *
 * Adds the required Javascript to all your Drupal pages to allow tracking by
 * the Umami website analytics.
 *
 */

use Drupal\Core\Cache\Cache;
@@ -33,7 +32,7 @@ function umami_analytics_page_attachments(array &$page) {
  $config = \Drupal::config('umami_analytics.settings');

  // Add module cache tags.
  $page['#cache']['tags'] = Cache::mergeTags(isset($page['#cache']['tags']) ? $page['#cache']['tags'] : [], $config->getCacheTags());
  $page['#cache']['tags'] = Cache::mergeTags($page['#cache']['tags'] ?? [], $config->getCacheTags());

  // Return if src or website_id are not set.
  if (empty($config->get('src')) || empty($config->get('website_id'))) {