예제 #1
0
 /**
  * Apply access check service to the route and parameters in the request.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request to access check.
  */
 protected function checkAccess(Request $request)
 {
     // The cacheability (if any) of this request's access check result must be
     // applied to the response.
     $access_result = $this->accessManager->checkRequest($request, $this->account, TRUE);
     // Allow a master request to set the access result for a subrequest: if an
     // access result attribute is already set, don't overwrite it.
     if (!$request->attributes->has(AccessAwareRouterInterface::ACCESS_RESULT)) {
         $request->attributes->set(AccessAwareRouterInterface::ACCESS_RESULT, $access_result);
     }
     if (!$access_result->isAllowed()) {
         throw new AccessDeniedHttpException($access_result instanceof AccessResultReasonInterface ? $access_result->getReason() : NULL);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $links = array();
     // General path-based breadcrumbs. Use the actual request path, prior to
     // resolving path aliases, so the breadcrumb can be defined by simply
     // creating a hierarchy of path aliases.
     $path = trim($this->context->getPathInfo(), '/');
     $path_elements = explode('/', $path);
     $exclude = array();
     // Don't show a link to the front-page path.
     $front = $this->config->get('page.front');
     $exclude[$front] = TRUE;
     // /user is just a redirect, so skip it.
     // @todo Find a better way to deal with /user.
     $exclude['user'] = TRUE;
     while (count($path_elements) > 1) {
         array_pop($path_elements);
         // Copy the path elements for up-casting.
         $route_request = $this->getRequestForPath(implode('/', $path_elements), $exclude);
         if ($route_request) {
             $access = $this->accessManager->checkRequest($route_request, $this->currentUser);
             if ($access) {
                 $title = $this->titleResolver->getTitle($route_request, $route_request->attributes->get(RouteObjectInterface::ROUTE_OBJECT));
             }
             if ($access) {
                 if (!isset($title)) {
                     // Fallback to using the raw path component as the title if the
                     // route is missing a _title or _title_callback attribute.
                     $title = str_replace(array('-', '_'), ' ', Unicode::ucfirst(end($path_elements)));
                 }
                 $links[] = Link::createFromRoute($title, $route_request->attributes->get(RouteObjectInterface::ROUTE_NAME), $route_request->attributes->get('_raw_variables')->all());
             }
         }
     }
     if ($path && $path != $front) {
         // Add the Home link, except for the front page.
         $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     }
     return array_reverse($links);
 }
 /**
  * Apply access check service to the route and parameters in the request.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request to access check.
  */
 protected function checkAccess(Request $request)
 {
     if (!$this->accessManager->checkRequest($request, $this->account)) {
         throw new AccessDeniedHttpException();
     }
 }