Issue #3303874 by alecsmrekar, Wim Leers, smustgrave: Early rendering issue in big_pipe_page_attachments() for controllers returning Response objects
(cherry picked from commit d6d5051fb9
)
merge-requests/3618/head
parent
0217ee0ae4
commit
1bca2d9b64
|
@ -281,7 +281,9 @@ class HtmlRenderer implements MainContentRendererInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow hooks to add attachments to $page['#attached'].
|
// Allow hooks to add attachments to $page['#attached'].
|
||||||
$this->invokePageAttachmentHooks($page);
|
$this->renderer->executeInRenderContext(new RenderContext(), function () use (&$page) {
|
||||||
|
$this->invokePageAttachmentHooks($page);
|
||||||
|
});
|
||||||
|
|
||||||
return [$page, $title];
|
return [$page, $title];
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,6 +217,12 @@ function common_test_page_attachments(array &$page) {
|
||||||
'#markup' => 'test',
|
'#markup' => 'test',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\Drupal::state()->get('common_test.hook_page_attachments.early_rendering', FALSE)) {
|
||||||
|
// Do some early rendering.
|
||||||
|
$element = ['#markup' => '123'];
|
||||||
|
\Drupal::service('renderer')->render($element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,3 +20,11 @@ common_test.js_and_css_querystring:
|
||||||
_controller: '\Drupal\common_test\Controller\CommonTestController::jsAndCssQuerystring'
|
_controller: '\Drupal\common_test\Controller\CommonTestController::jsAndCssQuerystring'
|
||||||
requirements:
|
requirements:
|
||||||
_access: 'TRUE'
|
_access: 'TRUE'
|
||||||
|
|
||||||
|
common_test.page_attachments:
|
||||||
|
path: '/common/attachments-test'
|
||||||
|
defaults:
|
||||||
|
_title: 'Attachments test'
|
||||||
|
_controller: '\Drupal\common_test\Controller\CommonTestController::attachments'
|
||||||
|
requirements:
|
||||||
|
_access: 'TRUE'
|
||||||
|
|
|
@ -92,4 +92,20 @@ class CommonTestController {
|
||||||
return new Response($output);
|
return new Response($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a sample response with some early rendering in
|
||||||
|
* common_test_page_attachments.
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
* A new Response object.
|
||||||
|
*/
|
||||||
|
public function attachments() {
|
||||||
|
\Drupal::state()->set('common_test.hook_page_attachments.early_rendering', TRUE);
|
||||||
|
$build = [
|
||||||
|
'#title' => 'A title',
|
||||||
|
'content' => ['#markup' => 'Some content'],
|
||||||
|
];
|
||||||
|
return \Drupal::service('main_content_renderer.html')->renderResponse($build, \Drupal::requestStack()->getCurrentRequest(), \Drupal::routeMatch());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
namespace Drupal\Tests\system\Kernel\Common;
|
namespace Drupal\Tests\system\Kernel\Common;
|
||||||
|
|
||||||
use Drupal\KernelTests\KernelTestBase;
|
use Drupal\KernelTests\KernelTestBase;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test page rendering hooks.
|
* Test page rendering hooks.
|
||||||
|
@ -77,4 +79,18 @@ class PageRenderTest extends KernelTestBase {
|
||||||
\Drupal::state()->set($module . '.' . $hook . '.render_array', FALSE);
|
\Drupal::state()->set($module . '.' . $hook . '.render_array', FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert that HtmlRenderer::invokePageAttachmentHooks is called in a render
|
||||||
|
* context.
|
||||||
|
*/
|
||||||
|
public function testHtmlRendererAttachmentsRenderContext(): void {
|
||||||
|
$this->enableModules(['common_test', 'system']);
|
||||||
|
\Drupal::state()->set('common_test.hook_page_attachments.render_url', TRUE);
|
||||||
|
$uri = '/common/attachments-test';
|
||||||
|
$request = new Request([], [], [], [], [], ['REQUEST_URI' => $uri, 'SCRIPT_NAME' => $uri]);
|
||||||
|
$response = \Drupal::service('http_kernel')->handle($request);
|
||||||
|
|
||||||
|
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue