You are here

class FarmAdminToolbar in farmOS 2.x

Provides a preRenderTray() method for the toolbar that uses farm.base.

@package Drupal\farm_ui_menu\Render\Element

Hierarchy

Expanded class hierarchy of FarmAdminToolbar

1 file declares its use of FarmAdminToolbar
farm_ui_menu.module in modules/core/ui/menu/farm_ui_menu.module
The farmOS UI Menu module.

File

modules/core/ui/menu/src/Render/Element/FarmAdminToolbar.php, line 13

Namespace

Drupal\farm_ui_menu\Render\Element
View source
class FarmAdminToolbar implements TrustedCallbackInterface {

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

  /**
   * Renders the farmOS toolbar's administration tray.
   *
   * This is a clone of AdminToolbar::preRenderTray() method, which sets the
   * menu root to farm.base instead of system.admin.
   *
   * @param array $build
   *   A renderable array.
   *
   * @return array
   *   The updated renderable array.
   *
   * @see \Drupal\admin_toolbar\Render\Element\AdminToolbar::preRenderTray()
   */
  public static function preRenderTray(array $build) {
    $menu_tree = \Drupal::service('toolbar.menu_tree');
    $parameters = new MenuTreeParameters();
    $parameters
      ->setRoot('farm.base')
      ->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
FarmAdminToolbar::preRenderTray public static function Renders the farmOS toolbar's administration tray.
FarmAdminToolbar::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.