Version 1
[yaffs-website] / web / core / modules / toolbar / src / Ajax / SetSubtreesCommand.php
diff --git a/web/core/modules/toolbar/src/Ajax/SetSubtreesCommand.php b/web/core/modules/toolbar/src/Ajax/SetSubtreesCommand.php
new file mode 100644 (file)
index 0000000..50c172e
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+namespace Drupal\toolbar\Ajax;
+
+use Drupal\Core\Ajax\CommandInterface;
+
+/**
+ * Defines an AJAX command that sets the toolbar subtrees.
+ */
+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),
+    ];
+  }
+
+}