Problem/Motivation

The links generated by the Extra Links deriver in the admin_toolbar_tools submodule cannot be altered in the UI, and for whatever reason, altering them in hook_preprocess_menu() did not effect any changes in the toolbar when I tried.

Steps to reproduce

Enable the admin_toolbar_tools submodule. It generates a bunch of links, but you can't change them.

Proposed resolution

Add an alter hook for the links generated by the deriver

Remaining tasks

Patch provided

User interface changes

N/A

API changes

New hook, hook_admin_toolbar_extra_links_alter() created

Data model changes

N/A

CommentFileSizeAuthor
#2 add_link_alter_hook-3398757-2.patch497 bytesalieffring
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alieffring created an issue. See original summary.

alieffring’s picture

StatusFileSize
new497 bytes

Adds hook_admin_toolbar_extra_links_alter()

ammaletu’s picture

I would very much appreciate this addition. The ExtraLinks class unfortunately adds some links which are unncessary and duplicate, and I haven't found a built-in way to remove them.

It works with the patch #2 and a hook like this:

/**
* Implements hook_admin_toolbar_extra_links_alter().
*/
function mymodule_admin_toolbar_extra_links_alter(&$links): void {
unset($links['media_library']);
}

ammaletu’s picture

I guess for this to be merged we need a test, right?

Prashant.c made their first commit to this issue’s fork.

prashant.c’s picture

Status: Active » Needs work

Thanks @alieffring and @Ammaletu.
Pushed the code by creating a issue fork, some documentation work is required in admin_toolbar_tools/admin_toolbar_tools.api.php .

ammaletu’s picture

Status: Needs work » Needs review

I corrected the doc block in the api file. There is currently only one test in this module, so I'll be bold here and set this to "needs review". :-)

dydave’s picture

Status: Needs review » Closed (won't fix)
Related issues: +#3488920: How can the menu links added by Admin Toolbar be changed?

Thanks a lot everyone for raising this issue and the code contributions, it's greatly appreciated!

It would seem the initial problem:

Enable the admin_toolbar_tools submodule. It generates a bunch of links, but you can't change them.

could already be achieved by using the approach detailed in comment #3488920-2: How can the menu links added by Admin Toolbar be changed?, with an implementation of hook_menu_links_discovered_alter.

Could you please try the suggested approach and let us know if this could work?

For the time being, closing this issue as Won't fix, since it seems there is already a proper solution provided by Drupal Core.

Feel free to re-open the issue if you consider these changes would still be needed, we would be glad to take another look.

Please let us know if you have any questions on this comment, this issue or the project in general, we would surely be glad to help.
Thanks again for your interest in the module and all your contributions! 🙂

dydave’s picture

ammaletu’s picture

Hi @dydave!

Thanks for pointing out the solution from the other issue. That indeed works as expected, and I don't know why I didn't find that hook before.

Here is how I remove a link from the menu now:

/**
 * Implements hook_menu_links_discovered_alter().
 */
function MY_MODULE_menu_links_discovered_alter(&$links): void {
  // Content > Media already links to the same page, so we don't need Content >
  // Media > Media library.
  unset($links['admin_toolbar_tools.extra_links:media_library']);
}
dydave’s picture

Thanks a lot Johannes (@ammaletu) for the positive feedback, it's greatly appreciated!

This will certainly help others with the same type of requirements and should be very helpful to us as an example when documenting related issue #3488920: How can the menu links added by Admin Toolbar be changed?.

Glad this could work for you 🙂
Thanks again for reporting back and documenting your changes! 🙏