4 * Contains \Drupal\bootstrap\Plugin\Preprocess\Breadcrumb.
7 namespace Drupal\bootstrap\Plugin\Preprocess;
9 use Drupal\bootstrap\Annotation\BootstrapPreprocess;
10 use Drupal\bootstrap\Utility\Variables;
11 use Drupal\Core\Template\Attribute;
15 * Pre-processes variables for the "breadcrumb" theme hook.
17 * @ingroup plugins_preprocess
19 * @BootstrapPreprocess("breadcrumb")
21 class Breadcrumb extends PreprocessBase implements PreprocessInterface {
26 public function preprocessVariables(Variables $variables) {
27 $breadcrumb = &$variables['breadcrumb'];
29 // Determine if breadcrumbs should be displayed.
30 $breadcrumb_visibility = $this->theme->getSetting('breadcrumb');
31 if (($breadcrumb_visibility == 0 || ($breadcrumb_visibility == 2 && \Drupal::service('router.admin_context')->isAdminRoute())) || empty($breadcrumb)) {
36 // Remove first occurrence of the "Home" <front> link, provided by core.
37 if (!$this->theme->getSetting('breadcrumb_home')) {
38 $front = Url::fromRoute('<front>')->toString();
39 foreach ($breadcrumb as $key => $link) {
40 if (isset($link['url']) && $link['url'] === $front) {
41 unset($breadcrumb[$key]);
47 if ($this->theme->getSetting('breadcrumb_title') && !empty($breadcrumb)) {
48 $request = \Drupal::request();
49 $route_match = \Drupal::routeMatch();
50 $page_title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
51 if (!empty($page_title)) {
53 'text' => $page_title,
54 'attributes' => new Attribute(['class' => ['active']]),
59 // Add cache context based on url.
60 $variables->addCacheContexts(['url']);