Version 1
[yaffs-website] / web / core / modules / system / src / Plugin / Block / SystemBreadcrumbBlock.php
1 <?php
2
3 namespace Drupal\system\Plugin\Block;
4
5 use Drupal\Core\Block\BlockBase;
6 use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
7 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
8 use Drupal\Core\Routing\RouteMatchInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10
11 /**
12  * Provides a block to display the breadcrumbs.
13  *
14  * @Block(
15  *   id = "system_breadcrumb_block",
16  *   admin_label = @Translation("Breadcrumbs")
17  * )
18  */
19 class SystemBreadcrumbBlock extends BlockBase implements ContainerFactoryPluginInterface {
20
21   /**
22    * The breadcrumb manager.
23    *
24    * @var \Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface
25    */
26   protected $breadcrumbManager;
27
28   /**
29    * The current route match.
30    *
31    * @var \Drupal\Core\Routing\RouteMatchInterface
32    */
33   protected $routeMatch;
34
35   /**
36    * Constructs a new SystemBreadcrumbBlock object.
37    *
38    * @param array $configuration
39    *   A configuration array containing information about the plugin instance.
40    * @param string $plugin_id
41    *   The plugin_id for the plugin instance.
42    * @param mixed $plugin_definition
43    *   The plugin implementation definition.
44    * @param \Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface $breadcrumb_manager
45    *   The breadcrumb manager.
46    * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
47    *   The current route match.
48    */
49   public function __construct(array $configuration, $plugin_id, $plugin_definition, BreadcrumbBuilderInterface $breadcrumb_manager, RouteMatchInterface $route_match) {
50     parent::__construct($configuration, $plugin_id, $plugin_definition);
51     $this->breadcrumbManager = $breadcrumb_manager;
52     $this->routeMatch = $route_match;
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
59     return new static(
60       $configuration,
61       $plugin_id,
62       $plugin_definition,
63       $container->get('breadcrumb'),
64       $container->get('current_route_match')
65     );
66   }
67
68   /**
69    * {@inheritdoc}
70    */
71   public function build() {
72     return $this->breadcrumbManager->build($this->routeMatch)->toRenderable();
73   }
74
75 }