core/modules/big_pipe/big_pipe.services.yml | 2 +- core/modules/big_pipe/src/Render/BigPipe.php | 92 ++++++++++++++++++---------- 2 files changed, 59 insertions(+), 35 deletions(-) diff --git a/core/modules/big_pipe/big_pipe.services.yml b/core/modules/big_pipe/big_pipe.services.yml index 32008fd..d47a39e 100644 --- a/core/modules/big_pipe/big_pipe.services.yml +++ b/core/modules/big_pipe/big_pipe.services.yml @@ -11,4 +11,4 @@ services: arguments: ['@current_user'] big_pipe: class: Drupal\big_pipe\Render\BigPipe - arguments: ['@renderer', '@session', '@ajax_response.attachments_processor', '@html_response.attachments_processor'] + arguments: ['@renderer', '@session', '@request_stack', '@http_kernel', '@event_dispatcher'] diff --git a/core/modules/big_pipe/src/Render/BigPipe.php b/core/modules/big_pipe/src/Render/BigPipe.php index b85e625..a053f9c 100644 --- a/core/modules/big_pipe/src/Render/BigPipe.php +++ b/core/modules/big_pipe/src/Render/BigPipe.php @@ -14,7 +14,9 @@ use Drupal\Core\Render\RendererInterface; use Drupal\Core\Render\AttachmentsResponseProcessorInterface; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -42,18 +44,25 @@ class BigPipe implements BigPipeInterface { protected $session; /** - * The AJAX response attachments processor service. + * The request stack. * - * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface + * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $ajaxResponseAttachmentsProcessor; + protected $requestStack; /** - * The HTML response attachments processor service. + * The HTTP kernel. * - * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface + * @var \Symfony\Component\HttpKernel\HttpKernelInterface */ - protected $htmlResponseAttachmentsProcessor; + protected $httpKernel; + + /** + * The event dispatcher. + * + * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface + */ + protected $eventDispatcher; /** * Constructs a new BigPipe class. @@ -62,16 +71,19 @@ class BigPipe implements BigPipeInterface { * The renderer. * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session * The session. - * @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $ajax_response_attachments_processor - * The AJAX response attachments processor service. - * @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $html_response_attachments_processor - * The HTML response attachments processor service. + * @param \Symfony\Component\HttpFoundation\RequestStack + * The request stack. + * @param \Symfony\Component\HttpKernel\HttpKernelInterface + * The HTTP kernel. + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher + * The event dispatcher. */ - public function __construct(RendererInterface $renderer, SessionInterface $session, AttachmentsResponseProcessorInterface $ajax_response_attachments_processor, AttachmentsResponseProcessorInterface $html_response_attachments_processor) { + public function __construct(RendererInterface $renderer, SessionInterface $session, RequestStack $request_stack, HttpKernelInterface $http_kernel, EventDispatcherInterface $event_dispatcher) { $this->renderer = $renderer; $this->session = $session; - $this->ajaxResponseAttachmentsProcessor = $ajax_response_attachments_processor; - $this->htmlResponseAttachmentsProcessor= $html_response_attachments_processor; + $this->requestStack = $request_stack; + $this->httpKernel = $http_kernel; + $this->eventDispatcher = $event_dispatcher; } /** @@ -163,6 +175,16 @@ public function sendContent($content, $attachments, array $placeholders) { // Sort placeholders by the order in which they appear in the markup. $order = $this->getPlaceholderOrder($content); + // A BigPipe response consists of a HTML response plus multiple embedded + // AJAX responses. To process the attachments of those AJAX responses, we + // need a fake request that is identical to the master request, but with + // one change: it must have the right Accept header, otherwise the work- + // around for a bug in IE9 will cause not JSON, but