0

I am modifying a module that extends PathBasedBreadcrumbBuilder, but that only has methods to add a link at the end of the bread and I want in certain cases to start the breadcrumb from scratch or add a link at the beginning of the breadcrumbs.

How can I do this?

1

I'm looking at this documentation and I think it says that you could start from scratch using:

$breadcrumb = new Breadcrumb();

And the class:

use Drupal\Core\Breadcrumb\Breadcrumb 
4
  • I tried that but get this error Error: Class 'Drupal\pup_taxonomy_breadcrumb\Breadcrumb' not found – Diana May 19 '17 at 15:39
  • now I added use Drupal\Core\Breadcrumb; And I get Error: Class 'Drupal\Core\Breadcrumb' not found – Diana May 19 '17 at 15:59
  • The comment(s) say it does not work - yet it is accepted? – Kevin May 20 '17 at 23:29
  • @Kevin I deleted the comments that led to the conclusion that she need the class use Drupal\Core\Breadcrumb\Breadcrumb. Sorry, I should have kept them next time... :) – Chris Happy May 21 '17 at 20:12
1

In your custom PathBasedBreadcrumbBuilder, you have to return true in the applies() method and additionally return your new Breadcrumb object in the build() method.

And you need this import

use Drupal\Core\Breadcrumb\Breadcrumb;

And in the services.yml of your module you must register the breadcrumb_builder plugin like so:

  preosasde.breadcrumb:
    class: Drupal\preosasde\PreosAsdeBreadcrumben
    arguments: ["@proreosservice", "@request_stack"]
    tags:
      - { name: breadcrumb_builder, priority: 100 }
1
  • Hi can you give me a link to the code for this applies method? – Diana May 19 '17 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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