You are here

public function AjaxResponseAttachmentsProcessor::processAttachments in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php \Drupal\Core\Ajax\AjaxResponseAttachmentsProcessor::processAttachments()
  2. 9 core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php \Drupal\Core\Ajax\AjaxResponseAttachmentsProcessor::processAttachments()

File

core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php, line 104

Class

AjaxResponseAttachmentsProcessor
Processes attachments of AJAX responses.

Namespace

Drupal\Core\Ajax

Code

public function processAttachments(AttachmentsInterface $response) {

  // @todo Convert to assertion once https://www.drupal.org/node/2408013 lands
  if (!$response instanceof AjaxResponse) {
    throw new \InvalidArgumentException('\\Drupal\\Core\\Ajax\\AjaxResponse instance expected.');
  }
  $request = $this->requestStack
    ->getCurrentRequest();
  if ($response
    ->getContent() == '{}') {
    $response
      ->setData($this
      ->buildAttachmentsCommands($response, $request));
  }
  return $response;
}