Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php \Drupal\Core\Breadcrumb\Breadcrumb
  2. 9 core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php \Drupal\Core\Breadcrumb\Breadcrumb

Used to return generated breadcrumbs with associated cacheability metadata.

Hierarchy

Expanded class hierarchy of Breadcrumb

12 files declare their use of Breadcrumb
BookBreadcrumbBuilder.php in core/modules/book/src/BookBreadcrumbBuilder.php
BreadcrumbManagerTest.php in core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php
BreadcrumbTest.php in core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php
CommentBreadcrumbBuilder.php in core/modules/comment/src/CommentBreadcrumbBuilder.php
ForumBreadcrumbBuilderBase.php in core/modules/forum/src/Breadcrumb/ForumBreadcrumbBuilderBase.php

... See full list

6 string references to 'Breadcrumb'
claro.info.yml in core/themes/claro/claro.info.yml
core/themes/claro/claro.info.yml
olivero.info.yml in core/themes/olivero/olivero.info.yml
core/themes/olivero/olivero.info.yml
testing_theme_optional_blocks.info.yml in core/profiles/testing_themes_blocks/themes/testing_theme_optional_blocks/testing_theme_optional_blocks.info.yml
core/profiles/testing_themes_blocks/themes/testing_theme_optional_blocks/testing_theme_optional_blocks.info.yml
testing_theme_required_blocks.info.yml in core/profiles/testing_themes_blocks/themes/testing_theme_required_blocks/testing_theme_required_blocks.info.yml
core/profiles/testing_themes_blocks/themes/testing_theme_required_blocks/testing_theme_required_blocks.info.yml
testing_theme_without_blocks.info.yml in core/profiles/testing_themes_blocks/themes/testing_theme_without_blocks/testing_theme_without_blocks.info.yml
core/profiles/testing_themes_blocks/themes/testing_theme_without_blocks/testing_theme_without_blocks.info.yml

... See full list

File

core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php, line 13

Namespace

Drupal\Core\Breadcrumb
View source
class Breadcrumb implements RenderableInterface, RefinableCacheableDependencyInterface {
  use RefinableCacheableDependencyTrait;

  /**
   * An ordered list of links for the breadcrumb.
   *
   * @var \Drupal\Core\Link[]
   */
  protected $links = [];

  /**
   * Gets the breadcrumb links.
   *
   * @return \Drupal\Core\Link[]
   */
  public function getLinks() {
    return $this->links;
  }

  /**
   * Sets the breadcrumb links.
   *
   * @param \Drupal\Core\Link[] $links
   *   The breadcrumb links.
   *
   * @return $this
   *
   * @throws \LogicException
   *   Thrown when setting breadcrumb links after they've already been set.
   */
  public function setLinks(array $links) {
    if (!empty($this->links)) {
      throw new \LogicException('Once breadcrumb links are set, only additional breadcrumb links can be added.');
    }
    $this->links = $links;
    return $this;
  }

  /**
   * Appends a link to the end of the ordered list of breadcrumb links.
   *
   * @param \Drupal\Core\Link $link
   *   The link appended to the breadcrumb.
   *
   * @return $this
   */
  public function addLink(Link $link) {
    $this->links[] = $link;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function toRenderable() {
    $build = [
      '#cache' => [
        'contexts' => $this->cacheContexts,
        'tags' => $this->cacheTags,
        'max-age' => $this->cacheMaxAge,
      ],
    ];
    if (!empty($this->links)) {
      $build += [
        '#theme' => 'breadcrumb',
        '#links' => $this->links,
      ];
    }
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Breadcrumb::$links protected property An ordered list of links for the breadcrumb.
Breadcrumb::addLink public function Appends a link to the end of the ordered list of breadcrumb links.
Breadcrumb::getLinks public function Gets the breadcrumb links.
Breadcrumb::setLinks public function Sets the breadcrumb links.
Breadcrumb::toRenderable public function Returns a render array representation of the object. Overrides RenderableInterface::toRenderable
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::getCacheContexts public function 4
CacheableDependencyTrait::getCacheMaxAge public function 4
CacheableDependencyTrait::getCacheTags public function 4
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function