/**
  * {@inheritdoc}
  */
 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;
 }
 /**
  * {@inheritdoc}
  */
 public function processAttachments(AttachmentsInterface $response)
 {
     // @todo Convert to assertion once https://www.drupal.org/node/2408013 lands
     if (!$response instanceof HtmlResponse) {
         throw new \InvalidArgumentException('\\Drupal\\Core\\Render\\HtmlResponse instance expected.');
     }
     $attached = $response->getAttachments();
     // Get the placeholders from attached and then remove them.
     $placeholders = $attached['html_response_placeholders'];
     unset($attached['html_response_placeholders']);
     $variables = $this->processAssetLibraries($attached, $placeholders);
     // Handle all non-asset attachments. This populates drupal_get_html_head()
     // and drupal_get_http_header().
     $all_attached = ['#attached' => $attached];
     drupal_process_attached($all_attached);
     // Get HTML head elements - if present.
     if (isset($placeholders['head'])) {
         $variables['head'] = drupal_get_html_head(FALSE);
     }
     // Now replace the placeholders in the response content with the real data.
     $this->renderPlaceholders($response, $placeholders, $variables);
     // Finally set the headers on the response.
     $headers = drupal_get_http_header();
     $this->setHeaders($response, $headers);
     return $response;
 }