Loading core/.phpstan-baseline.php +0 −12 Original line number Diff line number Diff line Loading @@ -35394,12 +35394,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/system/src/Hook/SystemHooks.php', ]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\system\\\\Hook\\\\SystemHooks\\:\\:pageAttachments\\(\\) has no return type specified\\.$#', 'count' => 1, 'path' => __DIR__ . '/modules/system/src/Hook/SystemHooks.php', ]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\system\\\\Hook\\\\SystemHooks\\:\\:pageTop\\(\\) has no return type specified\\.$#', Loading Loading @@ -35616,12 +35610,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/system/system.install', ]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Function _system_page_attachments\\(\\) has no return type specified\\.$#', 'count' => 1, 'path' => __DIR__ . '/modules/system/system.module', ]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Function system_authorized_batch_process\\(\\) has no return type specified\\.$#', core/lib/Drupal/Core/ProxyClass/Render/BareHtmlPageRenderer.php +8 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,14 @@ public function renderBarePage(array $content, $title, $page_theme_property, arr return $this->lazyLoadItself()->renderBarePage($content, $title, $page_theme_property, $page_additions); } /** * {@inheritdoc} */ public function systemPageAttachments(array &$page): void { $this->lazyLoadItself()->systemPageAttachments($page); } } } core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php +103 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ namespace Drupal\Core\Render; use Drupal\Component\Utility\UrlHelper; /** * Default bare HTML page renderer. */ Loading Loading @@ -62,7 +64,7 @@ public function renderBarePage(array $content, $title, $page_theme_property, arr // Add the bare minimum of attachments from the system module and the // current maintenance theme. _system_page_attachments($html['page']); $this->systemPageAttachments($html['page']); $this->renderer->renderRoot($html); $response = new HtmlResponse(); Loading @@ -70,7 +72,107 @@ public function renderBarePage(array $content, $title, $page_theme_property, arr // Process attachments, because this does not go via the regular render // pipeline, but will be sent directly. $response = $this->htmlResponseAttachmentsProcessor->processAttachments($response); return $response; } /** * Helper for system_page_attachments. * * SystemPageAttachment needs to be on BareHtmlPageRenderer. * When BareHtmlPageRenderer is called, the system module is not available. * PageAttachmentsHook can inject BareHtmlPageRenderer to use for system_page_attachments. * * @param array $page * The page to attach to. */ public function systemPageAttachments(array &$page): void { // Ensure the same CSS is loaded in template_preprocess_maintenance_page(). $page['#attached']['library'][] = 'system/base'; if (\Drupal::service('router.admin_context')->isAdminRoute()) { $page['#attached']['library'][] = 'system/admin'; } // Attach libraries used by this theme. $active_theme = \Drupal::theme()->getActiveTheme(); foreach ($active_theme->getLibraries() as $library) { $page['#attached']['library'][] = $library; } // Attach favicon. if (theme_get_setting('features.favicon')) { $favicon = theme_get_setting('favicon.url'); $type = theme_get_setting('favicon.mimetype'); $page['#attached']['html_head_link'][][] = [ 'rel' => 'icon', 'href' => UrlHelper::stripDangerousProtocols($favicon), 'type' => $type, ]; } // Get the major Drupal version. [$version] = explode('.', \Drupal::VERSION); // Attach default meta tags. $meta_default = [ // Make sure the Content-Type comes first because the IE browser may be // vulnerable to XSS via encoding attacks from any content that comes // before this META tag, such as a TITLE tag. 'system_meta_content_type' => [ '#tag' => 'meta', '#attributes' => [ 'charset' => 'utf-8', ], // Security: This always has to be output first. '#weight' => -1000, ], // Show Drupal and the major version number in the META GENERATOR tag. 'system_meta_generator' => [ '#type' => 'html_tag', '#tag' => 'meta', '#attributes' => [ 'name' => 'Generator', 'content' => 'Drupal ' . $version . ' (https://www.drupal.org)', ], ], // Attach default mobile meta tags for responsive design. 'MobileOptimized' => [ '#tag' => 'meta', '#attributes' => [ 'name' => 'MobileOptimized', 'content' => 'width', ], ], 'HandheldFriendly' => [ '#tag' => 'meta', '#attributes' => [ 'name' => 'HandheldFriendly', 'content' => 'true', ], ], 'viewport' => [ '#tag' => 'meta', '#attributes' => [ 'name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0', ], ], ]; foreach ($meta_default as $key => $value) { $page['#attached']['html_head'][] = [$value, $key]; } // Handle setting the "active" class on links by: // - loading the active-link library if the current user is authenticated; // - applying a response filter if the current user is anonymous. // @see \Drupal\Core\Link // @see \Drupal\Core\Utility\LinkGenerator::generate() // @see template_preprocess_links() // @see \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter $page['#cache']['contexts'][] = 'user.roles:authenticated'; if (\Drupal::currentUser()->isAuthenticated()) { $page['#attached']['library'][] = 'core/drupal.active-link'; } } } core/modules/system/src/Hook/PageAttachmentsHook.php 0 → 100644 +30 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\system\Hook; use Drupal\Core\Hook\Attribute\Hook; use Drupal\Core\Render\BareHtmlPageRendererInterface; /** * Implements hook_page_attachments() for the system module. */ final class PageAttachmentsHook { public function __construct( private readonly BareHtmlPageRendererInterface $bareHtmlPageRenderer, ) {} /** * Implements hook_page_attachments(). * * @see template_preprocess_maintenance_page() * @see \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter */ #[Hook('page_attachments')] public function pageAttachments(array &$page): void { $this->bareHtmlPageRenderer->systemPageAttachments($page); } } core/modules/system/src/Hook/SystemHooks.php +0 −11 Original line number Diff line number Diff line Loading @@ -194,17 +194,6 @@ public function filetransferInfo() { return $backends; } /** * Implements hook_page_attachments(). * * @see template_preprocess_maintenance_page() * @see \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter */ #[Hook('page_attachments')] public function pageAttachments(array &$page) { _system_page_attachments($page); } /** * Implements hook_js_settings_build(). * Loading Loading
core/.phpstan-baseline.php +0 −12 Original line number Diff line number Diff line Loading @@ -35394,12 +35394,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/system/src/Hook/SystemHooks.php', ]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\system\\\\Hook\\\\SystemHooks\\:\\:pageAttachments\\(\\) has no return type specified\\.$#', 'count' => 1, 'path' => __DIR__ . '/modules/system/src/Hook/SystemHooks.php', ]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\system\\\\Hook\\\\SystemHooks\\:\\:pageTop\\(\\) has no return type specified\\.$#', Loading Loading @@ -35616,12 +35610,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/system/system.install', ]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Function _system_page_attachments\\(\\) has no return type specified\\.$#', 'count' => 1, 'path' => __DIR__ . '/modules/system/system.module', ]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Function system_authorized_batch_process\\(\\) has no return type specified\\.$#',
core/lib/Drupal/Core/ProxyClass/Render/BareHtmlPageRenderer.php +8 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,14 @@ public function renderBarePage(array $content, $title, $page_theme_property, arr return $this->lazyLoadItself()->renderBarePage($content, $title, $page_theme_property, $page_additions); } /** * {@inheritdoc} */ public function systemPageAttachments(array &$page): void { $this->lazyLoadItself()->systemPageAttachments($page); } } }
core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php +103 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ namespace Drupal\Core\Render; use Drupal\Component\Utility\UrlHelper; /** * Default bare HTML page renderer. */ Loading Loading @@ -62,7 +64,7 @@ public function renderBarePage(array $content, $title, $page_theme_property, arr // Add the bare minimum of attachments from the system module and the // current maintenance theme. _system_page_attachments($html['page']); $this->systemPageAttachments($html['page']); $this->renderer->renderRoot($html); $response = new HtmlResponse(); Loading @@ -70,7 +72,107 @@ public function renderBarePage(array $content, $title, $page_theme_property, arr // Process attachments, because this does not go via the regular render // pipeline, but will be sent directly. $response = $this->htmlResponseAttachmentsProcessor->processAttachments($response); return $response; } /** * Helper for system_page_attachments. * * SystemPageAttachment needs to be on BareHtmlPageRenderer. * When BareHtmlPageRenderer is called, the system module is not available. * PageAttachmentsHook can inject BareHtmlPageRenderer to use for system_page_attachments. * * @param array $page * The page to attach to. */ public function systemPageAttachments(array &$page): void { // Ensure the same CSS is loaded in template_preprocess_maintenance_page(). $page['#attached']['library'][] = 'system/base'; if (\Drupal::service('router.admin_context')->isAdminRoute()) { $page['#attached']['library'][] = 'system/admin'; } // Attach libraries used by this theme. $active_theme = \Drupal::theme()->getActiveTheme(); foreach ($active_theme->getLibraries() as $library) { $page['#attached']['library'][] = $library; } // Attach favicon. if (theme_get_setting('features.favicon')) { $favicon = theme_get_setting('favicon.url'); $type = theme_get_setting('favicon.mimetype'); $page['#attached']['html_head_link'][][] = [ 'rel' => 'icon', 'href' => UrlHelper::stripDangerousProtocols($favicon), 'type' => $type, ]; } // Get the major Drupal version. [$version] = explode('.', \Drupal::VERSION); // Attach default meta tags. $meta_default = [ // Make sure the Content-Type comes first because the IE browser may be // vulnerable to XSS via encoding attacks from any content that comes // before this META tag, such as a TITLE tag. 'system_meta_content_type' => [ '#tag' => 'meta', '#attributes' => [ 'charset' => 'utf-8', ], // Security: This always has to be output first. '#weight' => -1000, ], // Show Drupal and the major version number in the META GENERATOR tag. 'system_meta_generator' => [ '#type' => 'html_tag', '#tag' => 'meta', '#attributes' => [ 'name' => 'Generator', 'content' => 'Drupal ' . $version . ' (https://www.drupal.org)', ], ], // Attach default mobile meta tags for responsive design. 'MobileOptimized' => [ '#tag' => 'meta', '#attributes' => [ 'name' => 'MobileOptimized', 'content' => 'width', ], ], 'HandheldFriendly' => [ '#tag' => 'meta', '#attributes' => [ 'name' => 'HandheldFriendly', 'content' => 'true', ], ], 'viewport' => [ '#tag' => 'meta', '#attributes' => [ 'name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0', ], ], ]; foreach ($meta_default as $key => $value) { $page['#attached']['html_head'][] = [$value, $key]; } // Handle setting the "active" class on links by: // - loading the active-link library if the current user is authenticated; // - applying a response filter if the current user is anonymous. // @see \Drupal\Core\Link // @see \Drupal\Core\Utility\LinkGenerator::generate() // @see template_preprocess_links() // @see \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter $page['#cache']['contexts'][] = 'user.roles:authenticated'; if (\Drupal::currentUser()->isAuthenticated()) { $page['#attached']['library'][] = 'core/drupal.active-link'; } } }
core/modules/system/src/Hook/PageAttachmentsHook.php 0 → 100644 +30 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\system\Hook; use Drupal\Core\Hook\Attribute\Hook; use Drupal\Core\Render\BareHtmlPageRendererInterface; /** * Implements hook_page_attachments() for the system module. */ final class PageAttachmentsHook { public function __construct( private readonly BareHtmlPageRendererInterface $bareHtmlPageRenderer, ) {} /** * Implements hook_page_attachments(). * * @see template_preprocess_maintenance_page() * @see \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter */ #[Hook('page_attachments')] public function pageAttachments(array &$page): void { $this->bareHtmlPageRenderer->systemPageAttachments($page); } }
core/modules/system/src/Hook/SystemHooks.php +0 −11 Original line number Diff line number Diff line Loading @@ -194,17 +194,6 @@ public function filetransferInfo() { return $backends; } /** * Implements hook_page_attachments(). * * @see template_preprocess_maintenance_page() * @see \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter */ #[Hook('page_attachments')] public function pageAttachments(array &$page) { _system_page_attachments($page); } /** * Implements hook_js_settings_build(). * Loading