Admin Toolbar Extra Tools items on /admin/index

Created on 6 February 2019, over 6 years ago
Updated 11 November 2019, over 5 years ago

When I visit /admin/index in Drupal, I'm presented with a list of menu items from Admin Toolbar Extra Tools.

I'd imagine that should be suppressed.

πŸ› Bug report
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States matt_paz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States tripodcreative

    Here's an easier way to do this:

    1). Copy admin-block.html.twig from core/modules/system/templates/admin-block.html.twig into your admin theme.
    2). Add this twig:

    {% set class = block.title %}
    {% set class = class|replace({' ':''}) %}
    {% set class = class|lower %}
    {%
      set classes = [
        'panel',
         class,
      ]
    %}
    
    Then, the <code><div{{ attributes.addClass(classes) }}>

    will include the class name of the region, in this case, admintoolbarsearch

    Then, in your admin theme, just

    div.admintoolbarsearch {
    display:none;
    }
    
  • πŸ‡©πŸ‡ͺGermany stefan.korn Jossgrund

    The list that admin_toolbar_tools generate on admin/index is really cluttering the UI and the link titles are often confusing.

    If you want to stop the output of admin_toolbar_tools before this actually is put on the site, you could use a Route Subscriber and override the core controller to exclude the links from admin_toolbar_tools.

    Like so:

    your_module.services.yml

    services:
      your_module.route_subscriber:
        class: Drupal\your_module\Routing\RouteSubscriber
        tags:
          - { name: event_subscriber }
    

    src/Routing/RouteSubscriber.php

    <?php
    
    namespace Drupal\your_module\Routing;
    
    use Drupal\Core\Routing\RouteSubscriberBase;
    use Symfony\Component\Routing\RouteCollection;
    
    class RouteSubscriber extends RouteSubscriberBase {
    
      protected function alterRoutes(RouteCollection $collection) {
        if ($route_index = $collection->get('system.admin_index')) {
          $route_index->setDefault('_controller', '\Drupal\your_module\Controller\AdminController::index');
        }
      }
    
    }
    

    src/Controller/AdminController

    <?php
    
    namespace Drupal\your_module\Controller;
    
    /*
     * hide the admin toolbar extra tools entries on admin/index as it clutters the UI.
     */
    class AdminController extends \Drupal\system\Controller\AdminController {
    
      public function index() {
        $output = parent::index();
        if (isset($output['#menu_items']['Admin Toolbar Extra Tools'])) {
          unset($output['#menu_items']['Admin Toolbar Extra Tools']);
        }
        return $output;
      }
    }
    
Production build 0.71.5 2024