HtmlResponseBigPipeSubscriber::onRespondEarly

public HtmlResponseBigPipeSubscriber::onRespondEarly(FilterResponseEvent $event)

Adds markers to the response necessary for the BigPipe render strategy.

Parameters

\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event: The event to process.

File

core/modules/big_pipe/src/EventSubscriber/HtmlResponseBigPipeSubscriber.php, line 44

Class

HtmlResponseBigPipeSubscriber
Response subscriber to replace the HtmlResponse with a BigPipeResponse.

Namespace

Drupal\big_pipe\EventSubscriber

Code

public function onRespondEarly(FilterResponseEvent $event) {
  $response = $event->getResponse();
  if (!$response instanceof HtmlResponse) {
    return;
  }

  // Wrap the scripts_bottom placeholder with a marker before and after,
  // because \Drupal\big_pipe\Render\BigPipe needs to be able to extract that
  // markup if there are no-JS BigPipe placeholders.
  // @see \Drupal\big_pipe\Render\BigPipe::sendPreBody()
  $attachments = $response->getAttachments();
  if (isset($attachments['html_response_attachment_placeholders']['scripts_bottom'])) {
    $scripts_bottom_placeholder = $attachments['html_response_attachment_placeholders']['scripts_bottom'];
    $content = $response->getContent();
    $content = str_replace($scripts_bottom_placeholder, '<drupal-big-pipe-scripts-bottom-marker>' . $scripts_bottom_placeholder . '<drupal-big-pipe-scripts-bottom-marker>', $content);
    $response->setContent($content);
  }
}
doc_Drupal
2016-10-29 09:18:55
Comments
Leave a Comment

Please login to continue.