You are here

function lazy_disabled_by_path in Lazy-load 8.2

Same name and namespace in other branches
  1. 8 lazy.module \lazy_disabled_by_path()

Checks whether lazy-load is disabled for the current path.

Parameters

string $disabled_paths: List of paths Lazy should be disabled.

Return value

bool Whether Lazy is disabled for the requested path.

2 calls to lazy_disabled_by_path()
LazyFilter::process in src/Plugin/Filter/LazyFilter.php
Performs the filter processing.
lazy_preprocess_field in ./lazy.module
Implements template_preprocess_field().

File

./lazy.module, line 236
Module file for Lazy-load.

Code

function lazy_disabled_by_path($disabled_paths) {
  if (empty($disabled_paths)) {
    return FALSE;
  }

  // Convert path to lowercase. This allows comparison of the same path
  // with different case. Ex: /Page, /page, /PAGE.
  $disabled_paths = mb_strtolower($disabled_paths);

  // Current path. Do not trim a trailing slash if that is the complete path.
  $current_path = \Drupal::service('path.current')
    ->getPath();
  $current_path = $current_path === '/' ? $current_path : rtrim($current_path, '/');

  // Path alias.
  $path_alias = \Drupal::service('path.alias_manager')
    ->getAliasByPath($current_path);
  $path_alias = mb_strtolower($path_alias);

  // If either returns TRUE, Lazy should be disabled for this path.
  $path_matcher = \Drupal::service('path.matcher')
    ->matchPath($current_path, $disabled_paths);
  $path_alias_matcher = \Drupal::service('path.matcher')
    ->matchPath($path_alias, $disabled_paths);
  return $path_alias_matcher || $path_matcher;
}