1

For several specific parts of a website, I'm using a custom BreadcrumbBuilder, like this:

...
class SpecificBreadcrumbBuilder implements BreadcrumbBuilderInterface
{    
    /**
     * @inheritdoc
     */
    public function applies(RouteMatchInterface $route_match)
    {
        $node = $route_match->getParameter('node');
        return $node->getType() == 'specificpage';
    }

    /**
     * @inheritdoc
     */
    public function build(RouteMatchInterface $route_match)
    {
        $node = $route_match->getParameter('node');

        $breadcrumb = new Breadcrumb();
        $breadcrumb->addCacheContexts(["url"]);
        $breadcrumb->addCacheTags(["node:{$node->nid->value}"]);

        $breadcrumb->addLink(Link::createFromRoute('Home', '<front>'));

        if (!empty($node->field_specific->value == '...')) {
          $breadcrumb->addLink(Link::createFromRoute('Specific pages', '<front>'));
          $breadcrumb->addLink(Link::createFromRoute($node->getTitle(), '<front>'));
        }

        return $breadcrumb;
    }
}

I would like to not use URLs for the two last links. Something like <nolink> (from the "Special Menu Items" module), but made from code.
I cannot find a way to add a text-only element to my Breadcrumb (and from what I can see, this class only have an addLink() function).

Any thoughts?

1 Answer 1

2

Drupal 8 has now a special <nolink> route to define empty links:

$breadcrumb->addlink(Link::createFromRoute('Empty link', '<nolink>'));

See issue (patch commited to 8.2.x): https://www.drupal.org/node/2693725

1
  • Thanks! I searched for it, but may have use <none> of something else.
    – zessx
    Jan 30, 2017 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.