Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
50.00% |
2 / 4 |
CRAP | |
35.71% |
5 / 14 |
Breadcrumb | |
0.00% |
0 / 1 |
|
50.00% |
2 / 4 |
15.56 | |
35.71% |
5 / 14 |
getLinks | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
setLinks | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
addLink | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
toRenderable | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 7 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\Core\Breadcrumb\Breadcrumb. | |
*/ | |
namespace Drupal\Core\Breadcrumb; | |
use Drupal\Core\Cache\RefinableCacheableDependencyInterface; | |
use Drupal\Core\Cache\RefinableCacheableDependencyTrait; | |
use Drupal\Core\Link; | |
use Drupal\Core\Render\RenderableInterface; | |
/** | |
* Used to return generated breadcrumbs with associated cacheability metadata. | |
*/ | |
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; | |
} | |
} |