The code in admin_toolbar_tools_menu_links_discovered_alter() adds links to the Content menu for adding a new entity, with a submenu of links for the different bundles, but this is hardcoded for node and media modules.
It would be better to do this generically, so all modules that have standard route names from DefaultHtmlRouteProvider get these links automatically.
Patch coming.
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | admin_toolbar.3028213.generalise-content-links.3-6-2.patch | 8.74 KB | joachim |
| #23 | admin_toolbar-3028213-23.patch | 8.73 KB | bhanu951 |
| #21 | admin_toolbar-3028213-21.patch | 8.75 KB | bhanu951 |
| #17 | admin_toolbar-3028213-17.patch | 8.46 KB | mandclu |
| #14 | 3028213-14.patch | 8.66 KB | paulocs |
Issue fork admin_toolbar-3028213
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:
- 3028213-generalize-creation-of
changes, plain diff MR !101
- 3.x
changes, plain diff MR !34
Comments
Comment #2
joachim commentedComment #3
oknateThe patch works great.
This is a good idea, but for me, it's adding unwanted links, for example for feeds and a custom entity type, symbol, and for brightcove videos. These types are types for which I wouldn't want an editor to try to add them manually.

So if we do this, I think we'd need a way to configure it by entity type, so it doesn't require an alter hook to suppress the links for certain entity types. I mean, I guess I could add an alter hook. But for me, right now, media and content are the only ones I want there.
I think this combined with a config would be ideal, where out of the box, only content and media are checked.
Now that I think about it, roles and permissions do handle this for every user except for the super user (user 1). This makes it more feasible without a custom config. But I still don't like the idea of requiring an alter to hook to suppress the add links for the super user. A config would be nicer.
Comment #4
oknateComment #5
chris matthews commentedComment #6
rpayanmComment #7
joachim commentedPatch #6 works for me (I can't RTBC as it's my work originally...)
> So if we do this, I think we'd need a way to configure it by entity type, so it doesn't require an alter hook to suppress the links for certain entity types. I mean, I guess I could add an alter hook. But for me, right now, media and content are the only ones I want there.
> I think this combined with a config would be ideal, where out of the box, only content and media are checked.
I can see there's a case for this -- since URL aliases became entities, I have a link to create them that's not relevant to me!
Setting to needs work for that.
I don't think this would belong in config. For starters, there might be circularity issues with reading a config entity to determine how to set up menu links for entities. But mainly, these sorts of aspects of entities are controlled in code in the entity class or its annotation.
So what I would suggest is:
- we introduce an entity annotation property that controls this
- implement an entity type alter hook to set this property to TRUE to all content entities that don't already set it
Custom entity types can then control this in their annotation, and for 3rd-party entity types, modules can also implement the hook and set the property to FALSE.
Comment #8
joachim commentedHere's a patch with that entity type property added.
Comment #9
adriancidAfter Apply the patch here is the difference, the Media menu item is different, should we keed the actual behavior or change to the new one comin in this patch?
Before:
After:
Comment #10
joachim commentedI don't have Media installed on the local dev I used for this, so I don't know what's going on there.
Are the menu items in the 'before' screenshot made by Media module or Admin Toolbar?
Comment #11
mandclu commentedI can reproduce what is shown in #9. On a fresh install of Drupal with admin toolbar and media, the admin toolbar has a nested menu to directly add media bundles. After applying the patch it does not.
I'll mention as an aside that the patch in #8 doesn't apply to the 3.0.0 release. Probably not a surprise, but it would be great to have a patch for the recommended release.
Also worth noting that in my testing install I was using a different content entity type, storage entities installed via the quick links module. After the patch the menu includes n "Add storage" menu item, but not nested under the "Storage data" menu item as I would have expected. Also, no links were generated for the storage bundles.
Comment #12
mandclu commentedHere's a new patch for the 8.x-2.x branch that should restore the current media structure, and add the same for other content entity types:
Please review.
Comment #13
steveoriolThis patch is it also necessary for version 3.0.0 of "admin_toolbar", because it does not apply on this version.
Comment #14
paulocsHere is patch for 3.x branch.
Comment #15
paulocsChanging target branch and re-adding tests.
Comment #16
dat deaf drupaler commentedThis patch for 3.x broke the storage module: Admin Toolbar 3.0.3 + Storage 1.1.0-beta2
Updated to 1.1.0-beta2 and getting this error when attempting to re-save storage bundle or creating a new storage bundle.
After disabling the 'Admin Toolbar Extra Tools' submodule (provided by Admin Toolbar module), error goes away.
Steps to reproduce
1. Install/enable admin_toolbar and admin_toolbar_tools.
2. Re-save existing storage bundle or create new storage type bundle.
TypeError: Argument 6 passed to Drupal\admin_toolbar_tools\Plugin\Derivative\ExtraLinks::__construct() must be an instance of Drupal\admin_toolbar_tools\Plugin\Derivative\EntityTypeBundleInfoInterface, instance of Drupal\Core\Entity\EntityTypeBundleInfo given, called in /web/modules/contrib/admin_toolbar/admin_toolbar_tools/src/Plugin/Derivative/ExtraLinks.php on line 87 in Drupal\admin_toolbar_tools\Plugin\Derivative\ExtraLinks->__construct() (line 68 of /web/modules/contrib/admin_toolbar/admin_toolbar_tools/src/Plugin/Derivative/ExtraLinks.php)
#0 /web/modules/contrib/admin_toolbar/admin_toolbar_tools/src/Plugin/Derivative/ExtraLinks.php(87): Drupal\admin_toolbar_tools\Plugin\Derivative\ExtraLinks->__construct()
#1 /web/core/lib/Drupal/Core/Plugin/Discovery/ContainerDerivativeDiscoveryDecorator.php(25): Drupal\admin_toolbar_tools\Plugin\Derivative\ExtraLinks::create()
#2 /web/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(99): Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator->getDeriver()
#3 /web/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(87): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDerivatives()
#4 /web/core/lib/Drupal/Core/Menu/MenuLinkManager.php(164): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDefinitions()
#5 /web/core/lib/Drupal/Core/Menu/MenuLinkManager.php(189): Drupal\Core\Menu\MenuLinkManager->getDefinitions()
#6 /web/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php(82): Drupal\Core\Menu\MenuLinkManager->rebuild()
#7 /web/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php(70): Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber->menuLinksRebuild()
#8 [internal function]: Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber->onRouterRebuild()
#9 /web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func()
#10 /web/core/lib/Drupal/Core/Routing/RouteBuilder.php(197): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#11 /web/core/lib/Drupal/Core/ProxyClass/Routing/RouteBuilder.php(83): Drupal\Core\Routing\RouteBuilder->rebuild()
#12 /web/core/lib/Drupal/Core/Extension/ModuleInstaller.php(363): Drupal\Core\ProxyClass\Routing\RouteBuilder->rebuild()
#13 /web/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(83): Drupal\Core\Extension\ModuleInstaller->install()
#14 /web/core/modules/system/src/Form/ModulesListForm.php(473): Drupal\Core\ProxyClass\Extension\ModuleInstaller->install()
#15 [internal function]: Drupal\system\Form\ModulesListForm->submitForm()
#16 /web/core/lib/Drupal/Core/Form/FormSubmitter.php(113): call_user_func_array()
#17 /web/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers()
#18 /web/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\Core\Form\FormSubmitter->doSubmitForm()
#19 /web/core/lib/Drupal/Core/Form/FormBuilder.php(321): Drupal\Core\Form\FormBuilder->processForm()
#20 /web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
#21 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
#22 /web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#23 /web/core/lib/Drupal/Core/Render/Renderer.php(578): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#24 /web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#25 /web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#26 /vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#27 /vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#28 /web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle()
#29 /web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle()
#30 /web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#31 /web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#32 /web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
#33 /web/modules/contrib/shield/src/ShieldMiddleware.php(91): Drupal\ban\BanMiddleware->handle()
#34 /web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\shield\ShieldMiddleware->handle()
#35 /web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#36 /vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#37 /web/core/lib/Drupal/Core/DrupalKernel.php(717): Stack\StackedHttpKernel->handle()
#38 /web/index.php(19): Drupal\Core\DrupalKernel->handle()
#39 {main}
Comment #17
mandclu commentedI believe the problem reported in #16 happened because the previous patch wouldn't apply cleanly. When I manually applied the changes to admin_toolbar 3.0.3 it appeared to work as expected. Here's a re-roll of the previous patch.
Comment #19
rkollerI've applied the patch in #17 to admin_toolbar
3.x-dev@devon a Drupal9.4.x-devinstallation withadmin_toolbar,admin_toolbar_toolsandadmin_toolbar_links_access_filterenabled. after applying the patch, while performing adrush cri already got the following error in the terminal:performed a patch-ignore afterwards. cleared caches and reapplied the patch and then triggered the clear caches command from within the admin menu. ran into a white screen with a slightly different stack trace:
Comment #21
bhanu951 commentedRe-roll for 3.x-dev branch
Comment #23
bhanu951 commentedComment #24
bhanu951 commentedComment #25
bhanu951 commentedHeads Up to anyone who is working on this issue .
If #2976861 gets committed, we need to proceed with a different approach as this patch is creating duplicate menu links for custom entities as mentioned in #2976861-83
Comment #26
erutan commentedApplying this patch on both 3.3.0 and dev of admin_toolbar gives me the following error after clearing caches. Drupal 9.5.3 and Feeds Beta 3. If I'm understanding this correctly, it seems like this patch should skip over a bad, missing, or misconfigured route vs fatally trying to create it. If this isn't seen as the responsibility of this project, this comment will just serve as an FYI for others (I'll leave it to others to set it to needs work).
Rolling back the patch and rebuilding the cache fixed the issue. :)
Comment #27
joachim commentedCleaning up the issue fork before rebasing the feature branch.
There's a bit of a mess here -- the feature branch, `3028213-generalize-creation-of` had no content on it, was on the main 3.x trunk, and the issue fork's 3.x had feature commits that correspond to patch #23!
Comment #29
joachim commentedMR 34 needs to be closed -- it's for the wrong branches.
Comment #33
joachim commentedRebase on 3.x.
Comment #34
joachim commented> Applying this patch on both 3.3.0 and dev of admin_toolbar gives me the following error after clearing caches. Drupal 9.5.3 and Feeds Beta 3.
I've just tried installing drupal/feeds (3.0.0), and the MR here doesn't crash.
I don't get an 'Add Feed' menu item though -- that is maybe because Feeds is adding a collection menu link itself? Needs further debugging.
Comment #35
joachim commentedHere's an updated patch for 3.6.2 for people using this with Composer patches.
Comment #36
dydave commentedHi Joachim (@joachim)!
Thanks a lot for the great work on this issue and for keeping the suggested code changes maintained.🙏
Just wanted to bring to your attention related issue #3550604: Automated Tests: Add Functional tests for classes ExtraLinks and SearchLinks which references this issue several times 🙂
It would be super helpful if you could please try to see how the changes in the merge request could integrate with the 'ExtraLinks' tests added in the related tests issue.
I would definitely be in favor of working on this issue and getting this change potentially integrated, as soon as we could have the 'ExtraLinks' and 'SearchLinks' automated tests in place.
Overall, I think this ticket is more of a refactoring task than a new feature, so with the tests in place, we should be able to move forward a bit quicker with these changes.
Could we also refactor the following links/labels? 'Add {entity type}' links under 'Structure' ('admin/structure')
'Add contact form'
https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
'Add media type' ==> I "think" you've already done this one ✅
https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
'Add content type' ==> I "think" you've already done this one ✅
https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
'Add vocabulary'
https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
'Add role'
https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
'Add view'
https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
Note that Block content and Comment types currently do not have an 'Add {entity type}' link added by the ExtraLinks class.... which should ideally also be standardized: the same behavior across all entity types would be easier to understand for anyone. 👌
Ideally, we wish we could remove exceptions with static label declarations in the
AdminToolbarToolsEntityCreationTraittest matrix from the other ticket, so we could use a more standardized method for the tests (instead of static labels), see:https://git.drupalcode.org/project/admin_toolbar/-/blob/af36beae3b23cab0...
It would be great if we could find a more generic way to approach the 'Add {entity type}' links added by the module under 'Structure' 👍
Then we should be able to come back to the 'Add {entity type} content' links, under the 'Content' menu.
Any feedback, comments or reviews on related issue or this ticket would be greatly appreciated.
Thanks in advance!