It would be great to add an option to move the node (content entity?) local tasks to the admin toolbar.

If you agree we could provide a patch.

Gin - Local tasks in admin menu

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

breidert created an issue. See original summary.

breidert’s picture

Category: Task » Feature request
saschaeggi’s picture

Cool idea, maybe we can make this a setting?

saschaeggi’s picture

Status: Active » Postponed (maintainer needs more info)

@breidert can you provide a patch for this?

breidert’s picture

Assigned: Unassigned » breidert
Status: Postponed (maintainer needs more info) » Active

@sascha - yes we are on in and have it almost ready.

bjcooper’s picture

How's it coming @breidert? We'd love to have this too and I'm willing to help. I was just about to re-invent this wheel.

breidert’s picture

@bjcooper - we have this already implemented and will commit this as patch to https://www.drupal.org/project/gin_toolbar in the next days.

Currently we are working on another feature in the toolbar: https://www.drupal.org/project/gin_toolbar/issues/3129304

The local tasks in the toolbar (this issue) would probably come in after that.

a.dmitriiev’s picture

Project: Gin Admin Theme » Gin Toolbar
Version: 8.x-3.0-alpha2 » 8.x-1.x-dev
a.dmitriiev’s picture

StatusFileSize
new3.08 KB

Here is the patch, that adds the local tasks to gin_toolbar. The only thing left so far is the icon. It should be added to gin, I guess.

a.dmitriiev’s picture

Status: Active » Needs review
bjcooper’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #9 appears to work perfectly (except no icon for the local task toolbar item, of course).

a.dmitriiev’s picture

StatusFileSize
new3.06 KB

Re-rolled patch

breidert’s picture

StatusFileSize
new65.52 KB

I tested the patch against the latest dev branch and it works as expected.

Two styling issues need to be solved:

  • The local tasks need an icon
  • The expanded menu needs the same styles as the other menus

However, since these styles are configured in the gin theme, style changes cannot be delivered with this patch.

Therefore, the status RTBC is ok from my point of view.

Below is a screenshot of an empty page with the patch installed.

Gin - Local tasks in admin menu

beunerd’s picture

Just a note that the patch in #12 is no longer working on dev. I'm getting:

Drupal\Core\Security\UntrustedCallbackException: Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was gin_toolbar_add_local_tasks_bar. See https://www.drupal.org/node/2966725 in Drupal\Core\Render\Renderer->doTrustedCallback() (line 96 of core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php).

a.dmitriiev’s picture

Assigned: breidert » a.dmitriiev
yjin’s picture

the patch in #9 #12 is no longer working on latest betas.

broon’s picture

I am late to this discussion, but I want to chip in the module Moderation Sidebar which works great on core's toolbar and basically puts all the local tasks into a sidebar already (hence the name).

However, it's not working with Gin Toolbar. Maybe you could join forces and support each other?

ciss’s picture

Status: Reviewed & tested by the community » Needs work

Setting status back to Needs Work according to #14.

saschaeggi’s picture

Any update on this? I think the placement should be different, but that's something I can work on afterwards.

a.dmitriiev’s picture

I will try to work on this this week, maybe even today.

a.dmitriiev’s picture

Status: Needs work » Needs review

I created the merge request with the updated functionality. Now pre_render uses class that implemets TrustedCallbackInterface.

dmitry.korhov’s picture

Status: Needs review » Needs work

Applied #21:

TypeError: Argument 1 passed to Drupal\Core\Render\Renderer::doTrustedCallback() must be callable, array given, called in /docroot/core/lib/Drupal/Core/Render/Renderer.php on line 781 in Drupal\Core\Render\Renderer->doTrustedCallback() (line 51 of core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php).

a.dmitriiev’s picture

Have you cleaned the cache after you applied the patch? According to PHP documentation array could be passed as callable if there is static method of class in array https://www.php.net/manual/en/language.types.callable.php .

seanb’s picture

Status: Needs work » Needs review
StatusFileSize
new4.53 KB

Attached is a reroll, plus I changed/fixed the things noted below.

  1. +++ b/gin_toolbar.module
    @@ -327,3 +331,73 @@ function _gin_toolbar_user__classic_toolbar() {
    +    $items['administration']['tray']['toolbar_administration']['#pre_render'][] = 'gin_toolbar_add_local_tasks_bar';
    

    Think we now need this to be a TrustedCallback.

  2. +++ b/gin_toolbar.module
    @@ -327,3 +331,73 @@ function _gin_toolbar_user__classic_toolbar() {
    +  if (!empty($local_tasks['tabs'])) {
    

    This seems to always render all local tasks in the admin menu (even for admin pages not related to entities). I found that a bit confusing. Maybe only add local tasks if the URL contains a content entity?

  3. +++ b/gin_toolbar.module
    @@ -327,3 +331,73 @@ function _gin_toolbar_user__classic_toolbar() {
    +        $items[] = $local_task['#link'];
    

    The link is missing some classes so the styling doesn't show up as expected.

  4. +++ b/gin_toolbar.module
    @@ -327,3 +331,73 @@ function _gin_toolbar_user__classic_toolbar() {
    +        if (strpos($key, 'edit_form') !== FALSE) {
    

    Since view is mostly the first tab, shouldn't this also be the main link?

  5. +++ b/gin_toolbar.module
    @@ -327,3 +331,73 @@ function _gin_toolbar_user__classic_toolbar() {
    +    // Add local tasks cacheable metadata to result build.
    

    This now only add the cache metadata on pages that have local tasks. That could mean another page could set the cache for the admin menu without local tasks, and after that the local task never show up. I think we should always apply the local task cache metadata since even when local tasks are empty, we did use them to build our output.

seanb’s picture

StatusFileSize
new55.12 KB

One other minor thing, the icon for the local tasks was already in the code, but it looks a little off. That might be a separate issue, but we could maybe fix it here. I think it is because the lines are a different width from the other icons.

Local task icon

seanb’s picture

Just found that when using the "admin_toolbar_links_access_filter" module you also need #3209342: Links without "original_link" are filtered by admin_toolbar_links_access_filter.

seanb’s picture

StatusFileSize
new2.62 KB
new4.68 KB

Actually needed a few more changes to make it work with "admin_toolbar_links_access_filter".

paulocs’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new43.1 KB
new47.03 KB

Looks good to me!
Thanks seanB.

christian.wiedemann’s picture

Looks great for me!

christian.wiedemann’s picture

Reroll MR2. Works now with beta17.

nuuou’s picture

Noticed a few oddities here. Screenshots attached.

  1. It looks like some classes are missing in Local Tasks, as menu items appear to be missing some styling (notably font styling and padding)
  2. The order of these Local Tasks is a bit wonky. Noticing this on all routes that have local tasks (both front-end with toolbar and actual "/admin" routes. The order of the Local Tasks never seems to match what's outputted normally through Drupal. Not sure if there's a pattern, but consistently the last item seems to be outputted first, at least
nuuou’s picture

StatusFileSize
new5.48 KB

Adjusted this, resolved the two issues I reported above. Modified existing patch with some additional attributes and respecting ordering.
Patch attached.

tijsdeboeck’s picture

Tested path #34, works like a charm! Thanks!

design.er’s picture

Patch #34 is working perfectly for me as well. ​Thanks for the implementation! :)

I second the question from #3: shouldn't this feature have an opt-out setting for site builders who prefer to use the local task tabs and avoid duplication?

seanb’s picture

After using this for a while one of our clients found it confusing to have the local tasks and primary tabs so asked us to take this out again. I think it would be nice to have a setting to enable/disable this.

nuuou’s picture

Hey all, I made a new related issue to this to add some more toolbar items my team needed.
I used the base of this new system from this current issue to extend to some other options, including Shortcuts and User Actions.

Depending on how this current issue moves forward, I'll watch to consolidate some stuff! Mostly didn't want to add to this issue as it's changed scope a bit for my need!

I hope to address some of the feedback here in that new issue as well, including the desire to make these a setting rather than just a default.

https://www.drupal.org/project/gin_toolbar/issues/3244394

undersound3’s picture

Was using Better Local Tasks before but this is even better.
Patch #34 works great on beta20.
No visual clutter in the frontend anymore! Thanks!

dieterholvoet’s picture

StatusFileSize
new297.03 KB

I'm not convinced about this approach to add the local tasks to the toolbar. I think it's confusing since the admin toolbar links are global and the local tasks are, well, local. I don't think they should be mixed.

I'm personally more fan of the Better Local Tasks approach, I have been doing the same thing for my own projects in custom code: rendering the local tasks block as usual and apply custom css to it. Here's what that looks like, floating to the bottom right of the screen:

Screenshot

Another option is integrating it with the new meta region since there's already an entity edit link anyway, but the problem(?) there is that that region is not sticky, it disappears when you scroll down the page.

dieterholvoet’s picture

StatusFileSize
new4.6 KB

For those interested in testing the current implementation, here's a version of the patch re-rolled against the dev branch.

nishruu’s picture

#41 Local tasks are working back for me with the 3.0.0-beta1 of gin and beta-21 of gin_toolbar. Thank you @DieterHolvoet.

I can confirm that https://www.drupal.org/project/gin_toolbar/issues/3244394 current implementation is outdated as @Nuuou said (I understood you were waiting on this issue to adapt your work).

chi’s picture

Would be nice if it highlighted the active tab.

svdhout’s picture

StatusFileSize
new217.79 KB

Just noticed that admin_toolbar has an option within admin_toolbar_tools that adds the local tasks to the secondary toolbar

admin tolbar local tasks

moshe weitzman’s picture

@svdhout Thanks for letting us know! Looks pretty good to me.

saschaeggi’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

Closing this in favor of the admin_toolbar solution mentioned in #44

beunerd’s picture

StatusFileSize
new4.96 KB

I liked the way the feature was implemented here better, so I've rebased the code to get a new patch that would apply.

berliner’s picture

StatusFileSize
new4.59 KB

Re-rolled for rc4

dieterholvoet’s picture

Maybe move this to a separate module instead of re-rolling? The issue is marked as Closed (won't fix).

flyke’s picture

Can confirm thatt patch #49 works with rc4.
I understand DieterHolvoet. But we have several projects at our company that are using gin + gin toolbar + local tasks at this moment, and we need to be able to update them. Changing the patch to a rc4 compatible patch in composer is the easiest way to do that for us at the moment, until a tried and tested separate module for this actually exists.