Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / src / PathBasedBreadcrumbBuilder.php
index 9f1a5590a0e3896eea294951d4fd1dace43e56f2..ebc5df0b756bf71f3570b9ca7a17369911aa83ce 100644 (file)
@@ -11,6 +11,7 @@ use Drupal\Core\Controller\TitleResolverInterface;
 use Drupal\Core\Link;
 use Drupal\Core\ParamConverter\ParamNotConvertedException;
 use Drupal\Core\Path\CurrentPathStack;
+use Drupal\Core\Path\PathMatcherInterface;
 use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
 use Drupal\Core\Routing\RequestContext;
 use Drupal\Core\Routing\RouteMatch;
@@ -79,6 +80,20 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface {
    */
   protected $currentUser;
 
+  /**
+   * The current path service.
+   *
+   * @var \Drupal\Core\Path\CurrentPathStack
+   */
+  protected $currentPath;
+
+  /**
+   * The patch matcher service.
+   *
+   * @var \Drupal\Core\Path\PathMatcherInterface
+   */
+  protected $pathMatcher;
+
   /**
    * Constructs the PathBasedBreadcrumbBuilder.
    *
@@ -98,8 +113,10 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface {
    *   The current user object.
    * @param \Drupal\Core\Path\CurrentPathStack $current_path
    *   The current path.
+   * @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
+   *   The path matcher service.
    */
-  public function __construct(RequestContext $context, AccessManagerInterface $access_manager, RequestMatcherInterface $router, InboundPathProcessorInterface $path_processor, ConfigFactoryInterface $config_factory, TitleResolverInterface $title_resolver, AccountInterface $current_user, CurrentPathStack $current_path) {
+  public function __construct(RequestContext $context, AccessManagerInterface $access_manager, RequestMatcherInterface $router, InboundPathProcessorInterface $path_processor, ConfigFactoryInterface $config_factory, TitleResolverInterface $title_resolver, AccountInterface $current_user, CurrentPathStack $current_path, PathMatcherInterface $path_matcher = NULL) {
     $this->context = $context;
     $this->accessManager = $access_manager;
     $this->router = $router;
@@ -108,6 +125,7 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface {
     $this->titleResolver = $title_resolver;
     $this->currentUser = $current_user;
     $this->currentPath = $current_path;
+    $this->pathMatcher = $path_matcher ?: \Drupal::service('path.matcher');
   }
 
   /**
@@ -124,6 +142,15 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface {
     $breadcrumb = new Breadcrumb();
     $links = [];
 
+    // Add the url.path.parent cache context. This code ignores the last path
+    // part so the result only depends on the path parents.
+    $breadcrumb->addCacheContexts(['url.path.parent']);
+
+    // Do not display a breadcrumb on the frontpage.
+    if ($this->pathMatcher->isFrontPage()) {
+      return $breadcrumb;
+    }
+
     // 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.
@@ -136,9 +163,6 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface {
     // /user is just a redirect, so skip it.
     // @todo Find a better way to deal with /user.
     $exclude['/user'] = TRUE;
-    // Add the url.path.parent cache context. This code ignores the last path
-    // part so the result only depends on the path parents.
-    $breadcrumb->addCacheContexts(['url.path.parent']);
     while (count($path_elements) > 1) {
       array_pop($path_elements);
       // Copy the path elements for up-casting.
@@ -160,13 +184,11 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface {
           $links[] = new Link($title, $url);
         }
       }
-
-    }
-    if ($path && '/' . $path != $front) {
-      // Add the Home link, except for the front page.
-      $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     }
 
+    // Add the Home link.
+    $links[] = Link::createFromRoute($this->t('Home'), '<front>');
+
     return $breadcrumb->setLinks(array_reverse($links));
   }