class InsertCommand in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Ajax/InsertCommand.php \Drupal\Core\Ajax\InsertCommand
Generic AJAX command for inserting content.
This command instructs the client to insert the given HTML using whichever jQuery DOM manipulation method has been specified in the #ajax['method'] variable of the element that triggered the request.
This command is implemented by Drupal.AjaxCommands.prototype.insert() defined in misc/ajax.js.
Hierarchy
- class \Drupal\Core\Ajax\InsertCommand implements CommandInterface, CommandWithAttachedAssetsInterface uses CommandWithAttachedAssetsTrait
Expanded class hierarchy of InsertCommand
Related topics
4 files declare their use of InsertCommand
- AjaxCommandsTest.php in core/
tests/ Drupal/ Tests/ Core/ Ajax/ AjaxCommandsTest.php - Contains \Drupal\Tests\Core\Ajax\AjaxCommandsTest.
- AjaxRenderer.php in core/
lib/ Drupal/ Core/ Render/ MainContent/ AjaxRenderer.php - Contains \Drupal\Core\Render\MainContent\AjaxRenderer.
- CommandsTest.php in core/
modules/ system/ src/ Tests/ Ajax/ CommandsTest.php - Contains \Drupal\system\Tests\Ajax\CommandsTest.
- EarlyRenderingTestController.php in core/
modules/ system/ tests/ modules/ early_rendering_controller_test/ src/ EarlyRenderingTestController.php - Contains \Drupal\early_rendering_controller_test\EarlyRenderingTestController.
File
- core/
lib/ Drupal/ Core/ Ajax/ InsertCommand.php, line 22 - Contains \Drupal\Core\Ajax\InsertCommand.
Namespace
Drupal\Core\AjaxView source
class InsertCommand implements CommandInterface, CommandWithAttachedAssetsInterface {
use CommandWithAttachedAssetsTrait;
/**
* A CSS selector string.
*
* If the command is a response to a request from an #ajax form element then
* this value can be NULL.
*
* @var string
*/
protected $selector;
/**
* The content for the matched element(s).
*
* Either a render array or an HTML string.
*
* @var string|array
*/
protected $content;
/**
* A settings array to be passed to any any attached JavaScript behavior.
*
* @var array
*/
protected $settings;
/**
* Constructs an InsertCommand object.
*
* @param string $selector
* A CSS selector.
* @param string|array $content
* The content that will be inserted in the matched element(s), either a
* render array or an HTML string.
* @param array $settings
* An array of JavaScript settings to be passed to any attached behaviors.
*/
public function __construct($selector, $content, array $settings = NULL) {
$this->selector = $selector;
$this->content = $content;
$this->settings = $settings;
}
/**
* Implements Drupal\Core\Ajax\CommandInterface:render().
*/
public function render() {
return array(
'command' => 'insert',
'method' => NULL,
'selector' => $this->selector,
'data' => $this
->getRenderedContent(),
'settings' => $this->settings,
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommandWithAttachedAssetsTrait:: |
protected | property | The attached assets for this Ajax command. | |
CommandWithAttachedAssetsTrait:: |
public | function | Gets the attached assets. | |
CommandWithAttachedAssetsTrait:: |
protected | function | Processes the content for output. | |
InsertCommand:: |
protected | property | The content for the matched element(s). | |
InsertCommand:: |
protected | property | A CSS selector string. | |
InsertCommand:: |
protected | property | A settings array to be passed to any any attached JavaScript behavior. | |
InsertCommand:: |
public | function |
Implements Drupal\Core\Ajax\CommandInterface:render(). Overrides CommandInterface:: |
6 |
InsertCommand:: |
public | function | Constructs an InsertCommand object. |