public function NgLightbox::isNgLightboxEnabledPath in NG Lightbox 8
Same name and namespace in other branches
- 2.x src/NgLightbox.php \Drupal\ng_lightbox\NgLightbox::isNgLightboxEnabledPath()
Checks whether a give path matches the ng-lightbox path rules. This function checks both internal paths and aliased paths.
Parameters
\Drupal\Core\Url $url: The Url object.
Return value
bool TRUE if it matches the given rules.
File
- src/
NgLightbox.php, line 74
Class
Namespace
Drupal\ng_lightboxCode
public function isNgLightboxEnabledPath(Url $url) {
// No lightbox on external Urls.
if ($url
->isExternal()) {
return FALSE;
}
// If we don't want to enable the Lightbox on admin pages.
if ($this->config
->get('skip_admin_paths') && $this->adminContext
->isAdminRoute()) {
return FALSE;
}
// @TODO, decide whether we want to try and support paths or to adopt routes
// like core is trying to force us into.
$path = strtolower($url
->toString());
// We filter out empty paths because some modules (such as Media) use
// theme_link() to generate links with empty paths and we filter out paths
// that do not start with a /, such as #hash-only URLs.
if (empty($path) || $path[0] !== '/') {
return FALSE;
}
// Remove the base path.
if ($base_path = \Drupal::request()
->getBasePath()) {
$path = substr($path, strlen($base_path));
}
// Check the cache, see if we've handled this before.
if (isset($this->matches[$path])) {
return $this->matches[$path];
}
// Normalise the patterns as well so they match the normalised paths.
$patterns = strtolower($this->config
->get('patterns'));
// Check for internal paths first which is much quicker than the alias lookup.
if ($this->pathMatcher
->matchPath($path, $patterns)) {
$this->matches[$path] = TRUE;
}
else {
// Now check for aliases paths.
$aliased_path = strtolower($this->aliasManager
->getAliasByPath($path));
if ($path != $aliased_path && $this->pathMatcher
->matchPath($aliased_path, $patterns)) {
$this->matches[$path] = TRUE;
}
else {
// No match.
$this->matches[$path] = FALSE;
}
}
return $this->matches[$path];
}