Fichier
-
src/
PathProcessor.php, line 97
Classe
- PathProcessor
- Processes the inbound path using path alias lookups.
Namespace
Drupal\subpathautoCode
public function processInbound($path, Request $request) {
$request_path = $this->getPath($request->getPathInfo());
// The path won't be processed if the path has been already modified by
// a path processor (including this one), or if this is a recursive call
// caused by ::isValidPath.
if ($request_path !== $path || $this->recursiveCall) {
return $path;
}
// Verify that the full path is not a redirect before checking its parts.
$path = $this->checkRedirectedPath($request_path);
$original_path = $path;
$max_depth = $this->getMaxDepth();
$subpath = [];
$i = 0;
while (($path_array = explode('/', ltrim($path, '/'))) && ($max_depth === 0 || $i < $max_depth)) {
$i++;
$subpath[] = array_pop($path_array);
if (empty($path_array)) {
break;
}
$path = '/' . implode('/', $path_array);
$processed_path = $this->pathProcessor
->processInbound($path, $request);
// If the path did not change, it might be that the alias is outdated.
// Check if a redirect has been created in the meantime and if.
if ($processed_path === $path) {
$processed_path = $this->checkRedirectedPath($path);
if ($path !== $processed_path) {
// Path $path is a redirect.
$processed_path = $this->pathProcessor
->processInbound($processed_path, $request);
}
}
if ($processed_path !== $path) {
$path = $processed_path . '/' . implode('/', array_reverse($subpath));
// Ensure that the path generated is valid. Call ::isValidPath to
// trigger path processors one more time to ensure proposed new path is
// valid. Since this method has generated the path, it should ignore all
// recursive calls made for this method.
$valid_path = $this->isValidPath($path);
// Use generated path if it's valid, otherwise give up and return
// original path to give other path processors chance to make their
// modifications for the path.
if ($valid_path) {
return $this->pathProcessor
->processInbound($path, $request);
}
break;
}
}
return $original_path;
}