You are here

function evaluate_visibility_conditions in Page Load Progress 8

Checks if the current URL is defined in the visibility conditions.

When being used, the visibility conditions allow to check if the current URL is one of the paths defined in the visibility conditions. Return statement is inverted by the is_negated() option.

Parameters

\Drupal\Core\Config\ImmutableConfig $config: Configuration of the module.

Return value

bool TRUE if the condition has been met, FALSE otherwise.

1 call to evaluate_visibility_conditions()
page_load_progress_page_attachments in ./page_load_progress.module
Implements hook_page_attachments().

File

./page_load_progress.module, line 23
Allows to attach page_load_progress assets to all pages.

Code

function evaluate_visibility_conditions(ImmutableConfig $config) {

  // Convert path to lowercase. This allows comparison of the same path
  // with different case. Ex: /Page, /page, /PAGE.
  $pages = mb_strtolower($config
    ->get('page_load_progress_request_path'));
  if (!$pages) {
    return TRUE;
  }

  // Compare the lowercase path alias (if any) and internal path.
  $path = \Drupal::service('path.current')
    ->getPath();

  // Do not trim a trailing slash if that is the complete path.
  $path = $path === '/' ? $path : rtrim($path, '/');
  $path_alias = mb_strtolower(\Drupal::service('path.alias_manager')
    ->getAliasByPath($path));
  $result = \Drupal::service('path.matcher')
    ->matchPath($path_alias, $pages) || $path != $path_alias && \Drupal::service('path.matcher')
    ->matchPath($path, $pages);
  return is_negated($config) ? !$result : $result;
}