Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/Ajax/AjaxResponse.php
- 9 core/lib/Drupal/Core/Ajax/AjaxResponse.php
Namespace
Drupal\Core\Ajax
File
core/lib/Drupal/Core/Ajax/AjaxResponse.php
View source
<?php
namespace Drupal\Core\Ajax;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Render\AttachmentsInterface;
use Drupal\Core\Render\AttachmentsTrait;
use Symfony\Component\HttpFoundation\JsonResponse;
class AjaxResponse extends JsonResponse implements AttachmentsInterface {
use AttachmentsTrait;
protected $commands = [];
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;
}
public function &getCommands() {
return $this->commands;
}
}
Classes