You are here

function yandex_metrics_show_counter in Yandex.Metrics 8.2

Same name and namespace in other branches
  1. 8.3 yandex_metrics.module \yandex_metrics_show_counter()
  2. 6.2 yandex_metrics.module \yandex_metrics_show_counter()
  3. 6 yandex_metrics.module \yandex_metrics_show_counter()
  4. 7.3 yandex_metrics.module \yandex_metrics_show_counter()
  5. 7 yandex_metrics.module \yandex_metrics_show_counter()
  6. 7.2 yandex_metrics.module \yandex_metrics_show_counter()

Returns FALSE if we need to disable counter on page.

Return value

bool

1 call to yandex_metrics_show_counter()
yandex_metrics_page_build in ./yandex_metrics.module
Implements hook_page_build(). Adds Yandex.Metrics counter code to the site footer.

File

./yandex_metrics.module, line 45
The main code of Yandex.Metrics Counter module.

Code

function yandex_metrics_show_counter() {
  $pages = Drupal::config('yandex_metrics.settings')
    ->get('visibility.path.pages');
  $visibility = Drupal::config('yandex_metrics.settings')
    ->get('visibility.path.visibility');
  $urls_equal = FALSE;
  if (!empty($pages)) {
    $pages_in_lowcase = drupal_strtolower($pages);
    $current_path = Drupal::service('path.alias_manager.cached')
      ->getPathAlias(current_path());
    $current_path = drupal_strtolower($current_path);

    // Compare internal and path alias.
    $path_match = drupal_match_path($current_path, $pages_in_lowcase);
    if ($path_match) {
      $urls_equal = TRUE;
    }
    else {

      // If path alias doesn't equal with current_path() then compare internal and current_path().
      $path_match = drupal_match_path(current_path(), $pages_in_lowcase);
      if ($current_path != current_path() && $path_match) {
        $urls_equal = TRUE;
      }
    }
  }
  if (!$visibility && $urls_equal) {
    return FALSE;
  }
  elseif (!$visibility && !$urls_equal) {
    return TRUE;
  }
  elseif ($visibility && $urls_equal) {
    return TRUE;
  }
  elseif ($visibility && !$urls_equal) {
    return FALSE;
  }
}