You are here

class AdminToolbar in Admin Toolbar 8.2

Same name and namespace in other branches
  1. 3.x src/Render/Element/AdminToolbar.php \Drupal\admin_toolbar\Render\Element\AdminToolbar

Class AdminToolbar.

@package Drupal\admin_toolbar\Render\Element

Hierarchy

Expanded class hierarchy of AdminToolbar

1 file declares its use of AdminToolbar
admin_toolbar.module in ./admin_toolbar.module
This is the module to create a drop-down menu for the core toolbar.

File

src/Render/Element/AdminToolbar.php, line 13

Namespace

Drupal\admin_toolbar\Render\Element
View source
class AdminToolbar implements TrustedCallbackInterface {

  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    return [
      'preRenderTray',
    ];
  }

  /**
   * Renders the toolbar's administration tray.
   *
   * This is a clone of core's toolbar_prerender_toolbar_administration_tray()
   * function, which uses setMaxDepth(4) instead of setTopLevelOnly().
   *
   * @param array $build
   *   A renderable array.
   *
   * @return array
   *   The updated renderable array.
   *
   * @see toolbar_prerender_toolbar_administration_tray()
   */
  public static function preRenderTray(array $build) {
    $menu_tree = \Drupal::service('toolbar.menu_tree');
    $parameters = new MenuTreeParameters();
    $parameters
      ->setRoot('system.admin')
      ->excludeRoot()
      ->setMaxDepth(4)
      ->onlyEnabledLinks();
    $tree = $menu_tree
      ->load(NULL, $parameters);
    $manipulators = [
      [
        'callable' => 'menu.default_tree_manipulators:checkAccess',
      ],
      [
        'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
      ],
      [
        'callable' => 'toolbar_tools_menu_navigation_links',
      ],
    ];
    $tree = $menu_tree
      ->transform($tree, $manipulators);
    $build['administration_menu'] = $menu_tree
      ->build($tree);
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdminToolbar::preRenderTray public static function Renders the toolbar's administration tray.
AdminToolbar::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.