Breadcrumb.php in Drupal 9
File
core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php
View source
<?php
namespace Drupal\Core\Breadcrumb;
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
use Drupal\Core\Cache\RefinableCacheableDependencyTrait;
use Drupal\Core\Link;
use Drupal\Core\Render\RenderableInterface;
class Breadcrumb implements RenderableInterface, RefinableCacheableDependencyInterface {
use RefinableCacheableDependencyTrait;
protected $links = [];
public function getLinks() {
return $this->links;
}
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;
}
public function addLink(Link $link) {
$this->links[] = $link;
return $this;
}
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;
}
}
Classes
Name |
Description |
Breadcrumb |
Used to return generated breadcrumbs with associated cacheability metadata. |