Commit 1880b794 authored by Dave Reid's avatar Dave Reid Committed by Adrian Cid Almaguer
Browse files

Issue #2759345: Option to move local tasks (tabs) into the Admin Toolbar

parent ab02785b
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Cache\CacheableMetadata;

/**
 * Implements hook_toolbar().
@@ -24,6 +25,49 @@ function admin_toolbar_tools_toolbar() {
    ],
    '#attached' => ['library' => ['admin_toolbar_tools/toolbar.icon']],
  ];

  // Toolbar item for primary local tasks.
  $config = \Drupal::config('admin_toolbar_tools.settings')->get('show_local_tasks');
  $items['admin_toolbar_local_tasks'] = [];
  CacheableMetadata::createFromObject($config)->applyTo($items['admin_toolbar_local_tasks']);

  if ($config) {
    $items['admin_toolbar_local_tasks'] += [
      '#type' => 'toolbar_item',
      '#wrapper_attributes' => [
        'class' => ['local-tasks-toolbar-tab'],
      ],
      // Put it after contextual toolbar item so when float right is applied
      // local tasks item will be first.
      '#weight' => 10,
      'tab' => [
        // We can't use #lazy_builder here because
        // ToolbarItem::preRenderToolbarItem will insert #attributes before
        // lazy_builder callback and this will produce Exception.
        // This means that for now we always render Local Tasks item even when
        // the tray is empty.
        '#type' => 'link',
        '#title' => t('Local Tasks'),
        '#url' => Url::fromRoute('<none>'),
        '#attributes' => [
          'class' => [
            'toolbar-icon',
            'toolbar-icon-local-tasks',
          ],
        ],
      ],
      'tray' => [
        'local_links' => [
          '#lazy_builder' => [
            'admin_toolbar_tools.helper:localTasksTrayLazyBuilder',
            [],
          ],
        ],
      ],
      '#attached' => ['library' => ['admin_toolbar_tools/toolbar.icon']],
    ];
  }

  return $items;
}

+2 −0
Original line number Diff line number Diff line
@@ -3,3 +3,5 @@ services:
    class: Drupal\admin_toolbar_tools\AdminToolbarToolsHelper
    arguments:
     - '@entity_type.manager'
     - '@plugin.manager.menu.local_task'
     - '@current_route_match'
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
max_bundle_number: 20
hoverintent_functionality: true
show_local_tasks: false
+3 −0
Original line number Diff line number Diff line
@@ -8,3 +8,6 @@ admin_toolbar_tools.settings:
    hoverintent_functionality:
      type: boolean
      label: 'Enable or disable hoverintent functionality'
    show_local_tasks:
      type: boolean
      label: 'Show local tasks in toolbar'
+12 −0
Original line number Diff line number Diff line
@@ -33,3 +33,15 @@
.toolbar-icon-8 .toolbar-icon-admin-toolbar-tools-help.active:before {
  background-image: url(../misc/icons/ffffff/drupal-8-logo.svg);
}

.toolbar-oriented .toolbar-bar .local-tasks-toolbar-tab {
  float: right;
}

.toolbar-horizontal .local-tasks-toolbar-tab .toolbar-menu {
  float: right;
}

.toolbar-bar .toolbar-icon-local-tasks:before {
  background-image: url(../misc/icons/bebebe/tasks.svg);
}
 No newline at end of file
Loading