function PathBasedBreadcrumbBuilder::getRequestForPath

Same name in other branches
  1. 9 core/modules/system/src/PathBasedBreadcrumbBuilder.php \Drupal\system\PathBasedBreadcrumbBuilder::getRequestForPath()
  2. 8.9.x core/modules/system/src/PathBasedBreadcrumbBuilder.php \Drupal\system\PathBasedBreadcrumbBuilder::getRequestForPath()
  3. 10 core/modules/system/src/PathBasedBreadcrumbBuilder.php \Drupal\system\PathBasedBreadcrumbBuilder::getRequestForPath()

Matches a path in the router.

Parameters

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.

1 call to PathBasedBreadcrumbBuilder::getRequestForPath()
PathBasedBreadcrumbBuilder::build in core/modules/system/src/PathBasedBreadcrumbBuilder.php
Builds the breadcrumb.

File

core/modules/system/src/PathBasedBreadcrumbBuilder.php, line 210

Class

PathBasedBreadcrumbBuilder
Defines a class to build path-based breadcrumbs.

Namespace

Drupal\system

Code

protected function getRequestForPath($path, array $exclude) {
    if (!empty($exclude[$path])) {
        return NULL;
    }
    $request = Request::create($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 (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|ResourceNotFoundException|MethodNotAllowedException|AccessDeniedHttpException|NotFoundHttpException) {
        return NULL;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.