function ThemeTestSubscriber::onRequest
Same name in other branches
- 9 core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php \Drupal\theme_test\EventSubscriber\ThemeTestSubscriber::onRequest()
- 10 core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php \Drupal\theme_test\EventSubscriber\ThemeTestSubscriber::onRequest()
- 11.x core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php \Drupal\theme_test\EventSubscriber\ThemeTestSubscriber::onRequest()
Generates themed output early in a page request.
See also
\Drupal\system\Tests\Theme\ThemeEarlyInitializationTest::testRequestListener()
File
-
core/
modules/ system/ tests/ modules/ theme_test/ src/ EventSubscriber/ ThemeTestSubscriber.php, line 56
Class
- ThemeTestSubscriber
- Theme test subscriber for controller requests.
Namespace
Drupal\theme_test\EventSubscriberCode
public function onRequest(GetResponseEvent $event) {
if ($this->currentRouteMatch
->getRouteName() === 'theme_test.request_listener') {
// First, force the theme registry to be rebuilt on this page request.
// This allows us to test a full initialization of the theme system in
// the code below.
drupal_theme_rebuild();
// Next, initialize the theme system by storing themed text in a global
// variable. We will use this later in
// theme_test_request_listener_page_callback() to test that even when the
// theme system is initialized this early, it is still capable of
// returning output and theming the page as a whole.
$more_link = [
'#type' => 'more_link',
'#url' => Url::fromRoute('user.page'),
'#attributes' => [
'title' => 'Themed output generated in a KernelEvents::REQUEST listener',
],
];
$GLOBALS['theme_test_output'] = $this->renderer
->renderPlain($more_link);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.