You are here

protected function Container::pathCheck in GoogleTagManager 8

Determines whether to insert the snippet based on the path settings.

Return value

bool TRUE if the path conditions are met; FALSE otherwise.

1 call to Container::pathCheck()
Container::insertSnippet in src/Entity/Container.php
Determines whether to insert the snippet on the response.

File

src/Entity/Container.php, line 449

Class

Container
Defines the container configuration entity.

Namespace

Drupal\google_tag\Entity

Code

protected function pathCheck() {
  $toggle = $this
    ->get('path_toggle');
  $paths = mb_strtolower($this
    ->get('path_list'));
  if (empty($paths)) {
    $satisfied = $toggle == GOOGLE_TAG_EXCLUDE_LISTED;
  }
  else {
    $request = \Drupal::request();
    $current_path = \Drupal::service('path.current');
    $alias_manager = \Drupal::service('path_alias.manager');
    $path_matcher = \Drupal::service('path.matcher');

    // @todo Are not some paths case sensitive???
    // Compare the lowercase path alias (if any) and internal path.
    $path = $current_path
      ->getPath($request);
    $path_alias = mb_strtolower($alias_manager
      ->getAliasByPath($path));
    $satisfied = $path_matcher
      ->matchPath($path_alias, $paths) || $path != $path_alias && $path_matcher
      ->matchPath($path, $paths);
    $satisfied = $toggle == GOOGLE_TAG_EXCLUDE_LISTED ? !$satisfied : $satisfied;
  }
  $this
    ->displayMessage('path check @satisfied', [
    '@satisfied' => $satisfied,
  ]);
  return $satisfied;
}