You are here

function lazy_disabled_by_path in Lazy-load 8

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

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

Parameters

$disabled_paths:

Return value

bool

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 235
Module file for Lazy-load.

Code

function lazy_disabled_by_path($disabled_paths) {

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

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

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