3 namespace Drupal\Core\Ajax;
6 * Generic AJAX command for inserting content.
8 * This command instructs the client to insert the given HTML using whichever
9 * jQuery DOM manipulation method has been specified in the #ajax['method']
10 * variable of the element that triggered the request.
12 * This command is implemented by Drupal.AjaxCommands.prototype.insert()
13 * defined in misc/ajax.js.
17 class InsertCommand implements CommandInterface, CommandWithAttachedAssetsInterface {
19 use CommandWithAttachedAssetsTrait;
22 * A CSS selector string.
24 * If the command is a response to a request from an #ajax form element then
25 * this value can be NULL.
32 * The content for the matched element(s).
34 * Either a render array or an HTML string.
41 * A settings array to be passed to any attached JavaScript behavior.
48 * Constructs an InsertCommand object.
50 * @param string $selector
52 * @param string|array $content
53 * The content that will be inserted in the matched element(s), either a
54 * render array or an HTML string.
55 * @param array $settings
56 * An array of JavaScript settings to be passed to any attached behaviors.
58 public function __construct($selector, $content, array $settings = NULL) {
59 $this->selector = $selector;
60 $this->content = $content;
61 $this->settings = $settings;
65 * Implements Drupal\Core\Ajax\CommandInterface:render().
67 public function render() {
70 'command' => 'insert',
72 'selector' => $this->selector,
73 'data' => $this->getRenderedContent(),
74 'settings' => $this->settings,