function HtmlResponseBigPipeSubscriber::onRespond

Same name in other branches
  1. 9 core/modules/big_pipe/src/EventSubscriber/HtmlResponseBigPipeSubscriber.php \Drupal\big_pipe\EventSubscriber\HtmlResponseBigPipeSubscriber::onRespond()
  2. 10 core/modules/big_pipe/src/EventSubscriber/HtmlResponseBigPipeSubscriber.php \Drupal\big_pipe\EventSubscriber\HtmlResponseBigPipeSubscriber::onRespond()
  3. 11.x core/modules/big_pipe/src/EventSubscriber/HtmlResponseBigPipeSubscriber.php \Drupal\big_pipe\EventSubscriber\HtmlResponseBigPipeSubscriber::onRespond()

Transforms a HtmlResponse to a BigPipeResponse.

Parameters

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

File

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

Class

HtmlResponseBigPipeSubscriber
Response subscriber to replace the HtmlResponse with a BigPipeResponse.

Namespace

Drupal\big_pipe\EventSubscriber

Code

public function onRespond(FilterResponseEvent $event) {
    $response = $event->getResponse();
    if (!$response instanceof HtmlResponse) {
        return;
    }
    $attachments = $response->getAttachments();
    // If there are no no-JS BigPipe placeholders, unwrap the scripts_bottom
    // markup.
    // @see onRespondEarly()
    // @see \Drupal\big_pipe\Render\BigPipe::sendPreBody()
    if (empty($attachments['big_pipe_nojs_placeholders'])) {
        $content = $response->getContent();
        $content = str_replace('<drupal-big-pipe-scripts-bottom-marker>', '', $content);
        $response->setContent($content);
    }
    // If there are neither BigPipe placeholders nor no-JS BigPipe placeholders,
    // there isn't anything dynamic in this response, and we can return early:
    // there is no point in sending this response using BigPipe.
    if (empty($attachments['big_pipe_placeholders']) && empty($attachments['big_pipe_nojs_placeholders'])) {
        return;
    }
    $big_pipe_response = new BigPipeResponse($response);
    $big_pipe_response->setBigPipeService($this->getBigPipeService($event));
    $event->setResponse($big_pipe_response);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.