Checks if there is a redirect for the path and if so, returns the new path.

Paramètres

string $path: The path to check.

Return value

string The new path.

1 call to PathProcessor::checkRedirectedPath()
PathProcessor::processInbound dans src/PathProcessor.php

Fichier

src/PathProcessor.php, line 214

Classe

PathProcessor
Processes the inbound path using path alias lookups.

Namespace

Drupal\subpathauto

Code

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;
}