Add possibility to remove a link from breadcrumbs

Created on 25 April 2018, over 6 years ago
Updated 29 August 2024, 4 months ago

Problem/Motivation

Working in a custom module I need to alter the breadcrumb for some cases and I use hook_system_breadcrumb_alter(). But I noticed I can't remove a Link from the breadcrumb using the methods ::getLinks() and ::setLinks() because of the logicException in the method ::setLinks() of the same class:

Once breadcrumb links are set, only additional breadcrumb links can be added.

I don't get the reason behind this. Is it cache? Can we have a method in the Drupal\Core\Breadcrumb\Breadcrumb class for this purpose? Or at least explain in the exception a bit more about the reasons this can't be done. I just tried this one that I attached using a comparison between route names and works as I expected.

Steps to reproduce

Call Breadcrumb::setLinks() on a Breadcrumb object that already has links.

Proposed resolution

  • Create ::removeLink()
  • Remove the logicException in ::getLinks()

Remaining tasks

Agree on what to do. Implement. Possible code is in the merge request. Tests are needed.

User interface changes

None.

Introduced terminology

None.

API changes

It will be possible to remove links from a Breadcrumb object.

Data model changes

None.

Release notes snippet

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
Menu systemΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ͺπŸ‡ΈSpain nachosalvador Elx

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs subsystem maintainer review

    It is used to alert the maintainer(s) of a particular core subsystem that an issue significantly impacts their subsystem, and their signoff is needed (see the governance policy draft for more information). Also, if you use this tag, make sure the issue component is set to the correct subsystem. If an issue significantly impacts more than one subsystem, use needs framework manager review instead.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024