public function HtmlResponseBigPipeSubscriber::onRespondEarly in Drupal 8
Same name and namespace in other branches
- 9 core/modules/big_pipe/src/EventSubscriber/HtmlResponseBigPipeSubscriber.php \Drupal\big_pipe\EventSubscriber\HtmlResponseBigPipeSubscriber::onRespondEarly()
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\EventSubscriberCode
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);
}
}