In drupal 7's admin_menu there was an option to move the local tasks (tabs) into the admin menu. I would love that feature parity here!

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

cwells created an issue. See original summary.

zmove’s picture

+1

eme’s picture

Well, why not... Just have to define where. In the white menu (top right) or add a new tab in the black one ?

chrisfromredfin’s picture

Issue summary: View changes
StatusFileSize
new73.08 KB

My hunch is I would most naturally see it as its own item, with the tabs then underneath it. So maybe another module, like admin_toolbar_extra_tabs, or maybe admin_toolbar_extra would have it as an option.

So I would see it with an icon, all the way to the left, like how admin_toolbar_extra does it now (so in the white section).

tabs layout mockup

zmove’s picture

The suggestion in #4 is ok, just add some css class to allow customization and it should cover most cases.

tinny’s picture

In the meantime I created a custom module and manually added them to the toolbar.

/**
 * Implements hook_toolbar().
 */
function MY_MODULE_toolbar() {
  $links = [];
  $local_tasks = menu_local_tasks();

  if (empty($local_tasks['tabs'])) {
    return $links;
  }

  foreach ($local_tasks['tabs'] as $route_name => $value) {
    // Add to array by #weight so that we have the correct order
    $links[$value['#weight']] = $value['#link'];
  }

  // Sort into correct order
  ksort($links);

  // Add the menu local tasks into the toolbar.
  $items['local_tasks'] = [
    '#type' => 'toolbar_item',
    'tab' => [
      '#type' => 'html_tag',
      '#tag' => 'button',
      '#value' => t('Edit'),
      '#attributes' => [
        'title' => t('Local tasks'),
        'class' => ['toolbar-icon', 'toolbar-icon-edit'],
      ],
    ],
    'tray' => [
      '#heading' => t('Local tasks'),
      'toolbar_administration' => [
        '#attributes' => [
          'class' => ['toolbar-menu'],
        ],
        '#links' => $links,
        '#theme' => 'links__toolbar_MY_MODULE',
      ],
    ],
    '#weight' => 1000,
  ];

  return $items;
}
danthorne’s picture

Thanks tinny.

miro_dietiker’s picture

StatusFileSize
new2.62 KB

We also discussed getting rid of the tabs to make the content area look more like it looks in public.

However, i would prefer a location that is related / near to the contextual edit toggle toolbar item:

pivica’s picture

Status: Active » Needs review
StatusFileSize
new117.42 KB
new2.24 KB

Here is a first patch based on comment 8 proposals. Looks like t:

Stuff that still needs to be done

  • Icon needed for toolbar item
  • Maybe option to turn this on/off?
  • Need a bit of help with render array caching for this.
berdir’s picture

+++ b/admin_toolbar_tools/admin_toolbar_tools.module
@@ -25,6 +25,50 @@ function admin_toolbar_tools_toolbar() {
+          // @todo - we need to put some cache context here!
+          //'#cache' => [],
+          '#theme' => 'links',
+          '#attributes' => [
+            'class' => ['toolbar-menu'],
+          ],
+          '#links' => $local_links,

I think some implementations were changed to use lazy builders so that the data doesn't have to be cached and is then added later, I think that would work quite well here as well.

You can see how that works in admin_toolbar_tools_toolbar() + admin_toolbar_tools_toolbar_alter().

If you do that you don't have to worry about cacheablity anymore.

adriancid’s picture

Status: Needs review » Needs work
StatusFileSize
new6.12 KB

Hi @pivica thanks for the patch.

If you don't have Local Tasks the arrow is shown:

Another thing, if you have visible the Toolbar and you click in the Local Tasks, the Toolbar is hidden, but if you click again in the Local Tasks button the Local Tasks are hidden but to show the Toolbar you need to go to click in Manage, and for this you made the whole tour from the right corner to the left corner.

pivica’s picture

Status: Needs work » Needs review
StatusFileSize
new4.02 KB
new5.36 KB
new67.21 KB

New patch. Changes:

  • Added lazy_builder callback for tray part.
  • Added toolbar icon. If somebody have better idea bring it on.
  • Some CSS fixes.

New screenshot:

Tried to add lazy_builder callback also for tab item but it's not possible. This means that we can not dynamically choose to not render tab item if there are no local tasks. For now, we will always render tab item. I don't have a good idea how to solve this. IMHO it's not a big deal to render tab item always if we don't figure some way to not show it.

Do we need a config option for this?

Another thing, if you have visible the Toolbar and you click in the Local Tasks, the Toolbar is hidden, but if you click again in the Local Tasks button the Local Tasks are hidden but to show the Toolbar you need to go to click in Manage, and for this you made the whole tour from the right corner to the left corner.

@adriancid sorry i was not able to understand exactly what is a problem here, can you add some screenshot or animated gif that is showing a problem?

miro_dietiker’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

If i checkout admin/structure/block in admin menu, it always only displays the first level..
My original intention was to use this functionality as a replacement to the other tabs below (such as hide the block).
Any idea how to address the second level?
(It's exposed as two blocks in admin UI..)

Bug: It seems to cache the tabs from the first load after a cache clear and always display those.
I guess this is test coverable.

miro_dietiker’s picture

I also see the Revisions tab displayed even if it is in fact then 403. So seems that access is not checked to hide inaccessible.

BTW the term "Edit" on the local task and the primary toolbar (top right for contextual) seems user confusion to me. We should not use the same term for two different things. But that's obviously a core issue...

adriancid’s picture

Issue summary: View changes
StatusFileSize
new90.26 KB

Hi @pivica

Another thing, if you have visible the Toolbar and you click in the Local Tasks, the Toolbar is hidden, but if you click again in the Local Tasks button the Local Tasks are hidden but to show the Toolbar you need to go to click in Manage, and for this you made the whole tour from the right corner to the left corner.

Let see if I can explain this (sorry for my english :-) )

When you click in the Local Tasks (the Toolbar with the Menu is hidden) you only see the local tasks, the other options (Content, Structure, ...) are not visible, and if you want to see this menus again, you need to move your mouse from the screen right side to the left side to click in the Manage option to show the Menus again.

Alexandre360’s picture

Any plan to commit this ? this issue begin to be old whereas there are solutions provided as patch...

adriancid’s picture

@Alexandre360 we don't have plans for the moment as we have things to review. See #13, #14 and #15

chris matthews’s picture

git apply -v move-local-tasks-into-admin-toolbar-2759345-12.patch

Checking patch admin_toolbar_tools/admin_toolbar_tools.module...
Hunk #1 succeeded at 24 (offset -1 lines).

Checking patch admin_toolbar_tools/css/tools.css...
Hunk #1 succeeded at 15 (offset 1 line).

Checking patch admin_toolbar_tools/src/ToolbarHandler.php...
error: admin_toolbar_tools/src/ToolbarHandler.php: No such file or directory
miro_dietiker’s picture

We switched away from this approach, so we (pivica, Berdir) likely won't push forward. Thus unsubscribing here.

We are using https://www.drupal.org/project/moderation_sidebar now and remove the tabs in the content area.

manuel.adan’s picture

At first glance, moderation_sidebar seems like a good alternative to say good bay to the taskbar, but according to its name and dependencies, it is oriented for websites with content moderation enabled, not fitting totally for simple sites with no content workflow. In addition to that, the taskbar is also present on other contexts apart from the entities canonical pages, could moderation_sidebar be useful to move the taskbar to the sidebar where it appears?

a.dmitriiev’s picture

@Chris Matthews I think you were trying to apply the patch against version 2.x, but it was made for version 1.x of the module. I am trying to re-roll the patch for version 2.x. Yes, issues described in #13, #14 and #15 will not be covered, but it would be the first step.

a.dmitriiev’s picture

StatusFileSize
new5.45 KB

Here is the re-rolled patch, maybe this will be a small push to restart the conversation here.

jcnventura’s picture

Status: Needs work » Needs review
jcnventura’s picture

Status: Needs review » Needs work

On Drupal 9, patch #22 throws this error:

Drupal\Core\Security\UntrustedCallbackException: Render #lazy_builder callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was Drupal\admin_toolbar_tools\AdminToolbarToolsHelper::localTasksTrayLazyBuil

shaktik’s picture

Assigned: Unassigned » shaktik

i am working on it.

shaktik’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Assigned: shaktik » Unassigned
Status: Needs work » Needs review
StatusFileSize
new25.38 KB
new35.63 KB
new6.17 KB
new1.94 KB

Hi @jcnventura,

Thanks for the review, please check the latest patch.

The #22patch no longer to applied on my sytem due to some chages came from diffrent patch code merged
index 708ea38..cffa113 100755

63,65c63,65
< @@ -15,3 +15,15 @@
<  .toolbar-icon-admin-toolbar-tools-help.active:before {
<    background-image: url(../misc/icons/ffffff/d8-item.svg);
---
> @@ -29,3 +29,15 @@
>  .toolbar-icon-8 .toolbar-icon-admin-toolbar-tools-help.active:before {
>    background-image: url(../misc/icons/ffffff/drupal-8-logo.svg);

, I reroll the patch #22 after that i fixed the issues D9.
Before patch

After patch

adriancid’s picture

Status: Needs review » Needs work

@shaktik, It doesn't work for me neither in d8 nor in d9. Can you pull the latest dev changes and apply your patch to see if is working for you?

shaktik’s picture

Status: Needs work » Needs review
StatusFileSize
new77.42 KB

Hi @adriancid,

I am able to apply the patch and working fine d8 and d9, below the output/screenshots.

bash-3.2# clear
bash-3.2# pwd
../D9/modules
bash-3.2# git clone --branch 8.x-2.x https://git.drupalcode.org/project/admin_toolbar.git
Cloning into 'admin_toolbar'...
remote: Enumerating objects: 148, done.
remote: Counting objects: 100% (148/148), done.
remote: Compressing objects: 100% (79/79), done.
remote: Total 1647 (delta 69), reused 107 (delta 47), pack-reused 1499
Receiving objects: 100% (1647/1647), 283.50 KiB | 534.00 KiB/s, done.
Resolving deltas: 100% (961/961), done.

bash-3.2# cd admin_toolbar/
bash-3.2# git status
On branch 8.x-2.x
Your branch is up to date with 'origin/8.x-2.x'.
nothing to commit, working tree clean
bash-3.2# git pull origin 8.x-2.x
From https://git.drupalcode.org/project/admin_toolbar
 * branch            8.x-2.x    -> FETCH_HEAD
Already up to date.
bash-3.2# curl
curl         curl-config
bash-3.2# curl https://www.drupal.org/files/issues/2020-08-20/2759345-26.patch | git apply -v
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6317  100  6317    0     0   5433      0  0:00:01  0:00:01 --:--:--  6021
Checking patch admin_toolbar_tools/admin_toolbar_tools.module...
Checking patch admin_toolbar_tools/admin_toolbar_tools.services.yml...
Checking patch admin_toolbar_tools/css/tools.css...
Checking patch admin_toolbar_tools/misc/icons/bebebe/tasks.svg...
Checking patch admin_toolbar_tools/src/AdminToolbarToolsHelper.php...
Applied patch admin_toolbar_tools/admin_toolbar_tools.module cleanly.
Applied patch admin_toolbar_tools/admin_toolbar_tools.services.yml cleanly.
Applied patch admin_toolbar_tools/css/tools.css cleanly.
Applied patch admin_toolbar_tools/misc/icons/bebebe/tasks.svg cleanly.
Applied patch admin_toolbar_tools/src/AdminToolbarToolsHelper.php cleanly.
bash-3.2# drush cr
Cache rebuild complete. [ok]

  • adriancid committed 5e3909e on 8.x-2.x authored by shaktik
    Issue #2759345 by pivica, shaktik, a.dmitriiev, adriancid, miro_dietiker...
adriancid’s picture

Status: Needs review » Fixed

Thanks

berdir’s picture

+++ b/admin_toolbar_tools/admin_toolbar_tools.module
@@ -24,6 +24,43 @@ function admin_toolbar_tools_toolbar() {
     '#attached' => ['library' => ['admin_toolbar_tools/toolbar.icon']],
   ];
+  // Toolbar item for primary local tasks.
+  // @todo - do we need some configuration to turn this on/off?
+  $items['admin_toolbar_local_tasks'] = [
+    '#type' => 'toolbar_item',

Hm, this feels important to me.

Not sure this module should automatically and unconditionally do this?

As mentioned before, we use https://www.drupal.org/project/issues/moderation_sidebar now, so this would duplicate that and you end up with two tasks elements?

skaught’s picture

EDIT: just below point

i see no 'option' to enable/disable.

skaught’s picture

Status: Fixed » Needs work

  • adriancid committed 02c2c18 on 8.x-2.x authored by shaktik
    Revert "Issue #2759345 by pivica, shaktik, a.dmitriiev, adriancid,...
skaught’s picture

re-add: i think dev head is broke. i am running composer builds on a project and reverted to previous. in /admin all pages WSOD with local bar commit

adriancid’s picture

dev is working fine for me.

berdir’s picture

Might be a special type of local task that breaks it, needs an actual error message/backtrace to investigate.

chrisfromredfin’s picture

StatusFileSize
new7.05 KB

This patch takes 22 against 8.x-2.x-dev and adds a config form to allow a checkbox and use it before the code that was added, removing the @todo. I was authoring with Drupal 9.0.3.

NOTE: Once I hit save, I need to flush caches in order to see the local tasks come or go. Do we need a drupal_flush_all_caches()
to happen when the config form is saved, or something else? Or is it OK to leave this with that expectation?

berdir’s picture

+++ b/admin_toolbar_tools/admin_toolbar_tools.module
@@ -24,6 +24,46 @@ function admin_toolbar_tools_toolbar() {
+
+  // Toolbar item for primary local tasks.
+  $show_local_tasks = \Drupal::config('admin_toolbar_tools.admintoolbartoolsconfig')->get('show_local_tasks');
+  if ($show_local_tasks) {
+    $items['admin_toolbar_local_tasks'] = [
+      '#type' => 'toolbar_item',
+      '#wrapper_attributes' => [
+        'class' => ['local-tasks-toolbar-tab'],
+      ],

Try adding cacheablity metadata to $items. Note that like https://api.drupal.org/api/drupal/core%21modules%21shortcut%21shortcut.m..., you need to always add it, not just if it's true.

So don't load the config value directly, get a $config object, then use https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Cache%21C... to create a cacheable metadata object from it and apply it to the empty $items['admin_toolbar_local_tasks() before the if.

skaught’s picture

#35
was Drupal 8.9.x. Seven theme. custom project theme.
-all /admin* page failed.
-public custom theme was find.

project is using serveral contrib modules adding other tasks.

#37
sorry, didn't have time to debug, just rebuilding composer to previous commit id .. was during 'working hrs'.

kitikonti’s picture

What is missing to get this working? I can't apply the patch from #38 to the latest dev. I also don't want to use the moderation sidebar module because it depends on the content moderation module which i dont use.

tinny’s picture

Status: Needs work » Needs review
StatusFileSize
new7.15 KB

I had a crack at applying #38 + #39 against 8.x-2.x.

tinny’s picture

Is there anything else I can do to push this along?

kitikonti’s picture

I dont see a icon and because of this on the mobile layout i dont see anything. You refere to an icon in "/modules/contrib/admin_toolbar/admin_toolbar_tools/misc/icons/bebebe/tasks.svg". In my case there is no "tasks.svg".

tinny’s picture

I'm not exactly sure how to add an image to a patch. The icon reference was referred to in a previous patch which I just kept.

kitikonti’s picture

The icon is in the patch from #26. Adding a icon works the same as every other file.

casey’s picture

I've published a module that does something similar; main difference is that it only moves "administrative" local tasks to the toolbar and only if not currently viewing a admin page.

https://www.drupal.org/project/admin_toolbar_tasks

It is complemented by https://www.drupal.org/project/admin_toolbar_messages that split of and display "administrative" status messages as part of the toolbar.

I also published https://www.drupal.org/project/admin_toolbar_entity_version that displays version information (published status or content moderation state) about the entity being viewed.

dave reid’s picture

StatusFileSize
new8.07 KB
new2.19 KB

I found that my local tasks were not ordered correctly by weight, so I added an Element::children() call to sort them by weight, and then Element::getVisibleChildren() to filter out any links that had an #access result that was not isAllowed(). I also restored the icon.

florianmuellerch’s picture

+1, used patch from @Dave Reid from #48 and it works like a charm!
Would love to see that being commited to the module!

chrisolof’s picture

Confirming that the patch in #48 works well.

  • adriancid committed c950496 on 8.x-2.x authored by Dave Reid
    Issue #2759345: Option to move local tasks (tabs) into the Admin Toolbar
    
adriancid’s picture

Status: Needs review » Fixed

  • adriancid committed 1880b79 on 3.x authored by Dave Reid
    Issue #2759345: Option to move local tasks (tabs) into the Admin Toolbar
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

larowlan’s picture

Just updated to 3.1.1.and noticed all my test started failing because all pages became uncacheable with Dynamic Page Cache.

Looking at the code difference between that and 3.1.0 and 3.1.1 this issue is the only one that stands out as cache related.

Also, shouldn't there have been an upgrade path to add the new setting?

larowlan’s picture

#3313767: Version 3.2.0 makes all pages uncacheable with dynamic page cache added for the critical regression this causes on all pages for logged in users