Same name and namespace in other branches
- 8.x-1.x src/EasyBreadcrumbBuilder.php \Drupal\easy_breadcrumb\EasyBreadcrumbBuilder::getRequestForPath()
Matches a path in the router.
Paramètres
string $path: The request path with a leading slash.
array $exclude: An array of paths or system paths to skip.
Return value
\Symfony\Component\HttpFoundation\Request A populated request object or NULL if the path couldn't be matched.
2 calls to EasyBreadcrumbBuilder::getRequestForPath()
- EasyBreadcrumbBuilder::build dans src/
EasyBreadcrumbBuilder.php - EasyBreadcrumbBuilder::setRouteContextFromRouteMatch dans src/
EasyBreadcrumbBuilder.php - Set request context from passed in $route_match if route is available.
Fichier
-
src/
EasyBreadcrumbBuilder.php, line 875
Classe
- EasyBreadcrumbBuilder
- Primary implementation for the Easy Breadcrumb builder.
Namespace
Drupal\easy_breadcrumbCode
protected function getRequestForPath($path, array $exclude) {
if (!empty($exclude[$path])) {
return NULL;
}
// Check to see if the path is actually a redirect, if it is, resolve it to
// its source before we create the request. Strip the starting slash,
// redirect module doesn't include it.
if ($this->moduleHandler
->moduleExists('redirect') && $this->config
->get(EasyBreadcrumbConstants::FOLLOW_REDIRECTS)) {
$redirect_path = $path;
if ($redirect_path[0] === '/') {
$redirect_path = substr($redirect_path, 1);
}
$language_prefix = $this->languageManager
->getCurrentLanguage()
->getId();
if (strpos($redirect_path, "{$language_prefix}/") === 0) {
$redirect_path = substr($redirect_path, strlen("{$language_prefix}/"));
}
/** @var \Drupal\redirect\Entity\Redirect $redirect */
if ($redirect = \Drupal::service('redirect.repository')->findMatchingRedirect($redirect_path, [], $this->languageManager
->getCurrentLanguage()
->getId())) {
$path = $redirect->getRedirectUrl()
->toString();
}
}
// @todo Use the RequestHelper once https://www.drupal.org/node/2090293 is
// fixed.
// The path in the request should start with a slash.
$request = Request::create('/' . ltrim($path, '/'));
// Performance optimization: set a short accept header to reduce overhead in
// AcceptHeaderMatcher when matching the request.
$request->headers
->set('Accept', 'text/html');
// Find the system path by resolving aliases, language prefix, etc.
$processed = $this->pathProcessor
->processInbound($path, $request);
if ($this->config
->get(EasyBreadcrumbConstants::HOME_SEGMENT_VALIDATION_SKIP)) {
unset($exclude[$this->siteConfig
->get('page.front')]);
}
if (empty($processed) || !empty($exclude[$processed])) {
// This resolves to the front page, which we already add.
return NULL;
}
$this->currentPath
->setPath($processed, $request);
// Attempt to match this path to provide a fully built request.
try {
$request->attributes
->add($this->router
->matchRequest($request));
return $request;
} catch (ParamNotConvertedException $e) {
return NULL;
} catch (ResourceNotFoundException $e) {
return NULL;
} catch (MethodNotAllowedException $e) {
return NULL;
} catch (AccessDeniedHttpException $e) {
return NULL;
}
}