public AjaxResponse::addCommand(CommandInterface $command, $prepend = FALSE)
Add an AJAX command to the response.
\Drupal\Core\Ajax\CommandInterface $command: An AJAX command object implementing CommandInterface.
bool $prepend: A boolean which determines whether the new command should be executed before previously added commands. Defaults to FALSE.
AjaxResponse The current AjaxResponse.
public function addCommand(CommandInterface $command, $prepend = FALSE) { if ($prepend) { array_unshift($this->commands, $command->render()); } else { $this->commands[] = $command->render(); } if ($command instanceof CommandWithAttachedAssetsInterface) { $assets = $command->getAttachedAssets(); $attachments = [ 'library' => $assets->getLibraries(), 'drupalSettings' => $assets->getSettings(), ]; $attachments = BubbleableMetadata::mergeAttachments($this->getAttachments(), $attachments); $this->setAttachments($attachments); } return $this; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Ajax!AjaxResponse.php/function/AjaxResponse::addCommand/8.1.x