You are here

class GinToolbar in Gin Toolbar 8

Class GinToolbar.

@package Drupal\gin_toolbar\Render\Element

Hierarchy

Expanded class hierarchy of GinToolbar

1 file declares its use of GinToolbar
gin_toolbar.module in ./gin_toolbar.module
gin_toolbar.module

File

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

Namespace

Drupal\gin_toolbar\Render\Element
View source
class GinToolbar 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 adds active trail information and which uses setMaxDepth(4)
   * instead of setTopLevelOnly() in case the Admin Toolbar module is installed.
   *
   * @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');
    $activeTrail = \Drupal::service('gin_toolbar.active_trail')
      ->getActiveTrailIds('admin');
    $parameters = (new MenuTreeParameters())
      ->setActiveTrail($activeTrail)
      ->setRoot('system.admin')
      ->excludeRoot()
      ->setTopLevelOnly()
      ->onlyEnabledLinks();
    if (\Drupal::moduleHandler()
      ->moduleExists('admin_toolbar')) {
      $parameters
        ->setMaxDepth(4);
    }
    $tree = $menu_tree
      ->load('admin', $parameters);
    $manipulators = [
      [
        'callable' => 'menu.default_tree_manipulators:checkAccess',
      ],
      [
        'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
      ],
      [
        'callable' => 'gin_toolbar_tools_menu_navigation_links',
      ],
    ];
    $tree = $menu_tree
      ->transform($tree, $manipulators);
    $build['administration_menu'] = $menu_tree
      ->build($tree);
    $build['#cache']['contexts'][] = 'route.menu_active_trails:admin';
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GinToolbar::preRenderTray public static function Renders the toolbar's administration tray.
GinToolbar::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.