Checks if there is a redirect for the path and if so, returns the new path.
Parameters
string $path: The path to check.
Return value
string The new path.
1 call to PathProcessor::checkRedirectedPath()
File
-
src/
PathProcessor.php, line 214
Class
- PathProcessor
- Processes the inbound path using path alias lookups.
Namespace
Drupal\subpathautoCode
protected function checkRedirectedPath(string $path) {
if (!isset($this->hasRedirectModuleSupport)) {
$this->hasRedirectModuleSupport = $this->moduleHandler
->moduleExists('redirect') && $this->configFactory
->get('subpathauto.settings')
->get('redirect_support');
}
if ($this->hasRedirectModuleSupport) {
// Loads and check if the current path has a redirect.
$redirects = \Drupal::service('redirect.repository')->findBySourcePath(ltrim($path, '/'));
if (!empty($redirects)) {
$redirect = reset($redirects)->getRedirect();
$url = Url::fromUri($redirect['uri']);
// If there is a redirect towards an external or unrouted source, don't
// do anything as it's not relevant for constructing or deconstructing
// an alias.
if ($url->isExternal() || !$url->isRouted()) {
return $path;
}
// Return the internal path, the unaliased path of the URL.
return '/' . $url->getInternalPath();
}
}
return $path;
}