Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HtmlResponseBigPipeSubscriber.php

function HtmlResponseBigPipeSubscriber::onRespondEarly

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

Parameters

\Symfony\Component\HttpKernel\Event\ResponseEvent $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(ResponseEvent $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);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal