1

I am trying to add a link to a taxonomy landing page, like this

$breadcrumbs->addLink(Link::createFromRoute($term_name,"/taxonomy/term/$tid"));

but I get the following error : Symfony\Component\Routing\Exception\RouteNotFoundException: Route "/taxonomy/term/2041" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 187 of C:\drupaldevsites\pup-dev\docroot\core\lib\Drupal\Core\Routing\RouteProvider.php).

2

2 Answers 2

7

The argument has to be a route name.

Try:

$breadcrumbs->addLink(Link::createFromRoute($term_name, "entity.taxonomy_term.canonical", ["taxonomy_term" => $tid]));

See the docs for this method.

0
0

Get the route name using :

dump(\Drupal::routeMatch()->getRouteName());

then use that route name :

$myBreadcrumbs [] = Link::createFromRoute('News Centre', 'ROUTE_NAME');

Your Answer

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

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