Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
71
core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php
Normal file
71
core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Breadcrumb\Breadcrumb.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Breadcrumb;
|
||||
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Link;
|
||||
|
||||
/**
|
||||
* Used to return generated breadcrumbs with associated cacheability metadata.
|
||||
*
|
||||
* @todo implement RenderableInterface once https://www.drupal.org/node/2529560 lands.
|
||||
*/
|
||||
class Breadcrumb extends CacheableMetadata {
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -32,9 +32,8 @@ interface BreadcrumbBuilderInterface {
|
|||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
|
||||
* The current route match.
|
||||
*
|
||||
* @return \Drupal\Core\Link[]
|
||||
* An array of links for the breadcrumb. Returning an empty array will
|
||||
* suppress all breadcrumbs.
|
||||
* @return \Drupal\Core\Breadcrumb\Breadcrumb
|
||||
* A breadcrumb.
|
||||
*/
|
||||
public function build(RouteMatchInterface $route_match);
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ class BreadcrumbManager implements ChainBreadcrumbBuilderInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(RouteMatchInterface $route_match) {
|
||||
$breadcrumb = array();
|
||||
$breadcrumb = new Breadcrumb();
|
||||
$context = array('builder' => NULL);
|
||||
// Call the build method of registered breadcrumb builders,
|
||||
// until one of them returns an array.
|
||||
|
@ -85,11 +85,9 @@ class BreadcrumbManager implements ChainBreadcrumbBuilderInterface {
|
|||
continue;
|
||||
}
|
||||
|
||||
$build = $builder->build($route_match);
|
||||
$breadcrumb = $builder->build($route_match);
|
||||
|
||||
if (is_array($build)) {
|
||||
// The builder returned an array of breadcrumb links.
|
||||
$breadcrumb = $build;
|
||||
if ($breadcrumb instanceof Breadcrumb) {
|
||||
$context['builder'] = $builder;
|
||||
break;
|
||||
}
|
||||
|
@ -99,7 +97,7 @@ class BreadcrumbManager implements ChainBreadcrumbBuilderInterface {
|
|||
}
|
||||
// Allow modules to alter the breadcrumb.
|
||||
$this->moduleHandler->alter('system_breadcrumb', $breadcrumb, $route_match, $context);
|
||||
// Fall back to an empty breadcrumb.
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue