You are here

class SetSubtreesCommand in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/toolbar/src/Ajax/SetSubtreesCommand.php \Drupal\toolbar\Ajax\SetSubtreesCommand

Defines an AJAX command that sets the toolbar subtrees.

Hierarchy

Expanded class hierarchy of SetSubtreesCommand

1 file declares its use of SetSubtreesCommand
ToolbarController.php in core/modules/toolbar/src/Controller/ToolbarController.php

File

core/modules/toolbar/src/Ajax/SetSubtreesCommand.php, line 10

Namespace

Drupal\toolbar\Ajax
View source
class SetSubtreesCommand implements CommandInterface {

  /**
   * The toolbar subtrees.
   *
   * @var array
   */
  protected $subtrees;

  /**
   * Constructs a SetSubtreesCommand object.
   *
   * @param array $subtrees
   *   The toolbar subtrees that will be set.
   */
  public function __construct($subtrees) {
    $this->subtrees = $subtrees;
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    return [
      'command' => 'setToolbarSubtrees',
      'subtrees' => array_map('strval', $this->subtrees),
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SetSubtreesCommand::$subtrees protected property The toolbar subtrees.
SetSubtreesCommand::render public function Return an array to be run through json_encode and sent to the client. Overrides CommandInterface::render
SetSubtreesCommand::__construct public function Constructs a SetSubtreesCommand object.