diff --git a/core/includes/common.inc b/core/includes/common.inc index c0109b9..9ec0e86 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3568,19 +3568,11 @@ function drupal_prepare_page($page) { drupal_set_page_content($page); $page = element_info('page'); } - // Special front controllers (like install.php and update.php) are returning a - // proper #type 'page' render array (in order to set a custom #theme template), - // so just ensure that #type 'page' is complete. - elseif (isset($page['#type']) && $page['#type'] === 'page') { - $page += element_info('page'); - } // Modules can add elements to $page as needed in hook_page_build(). - if (!defined('MAINTENANCE_MODE')) { - foreach (\Drupal::moduleHandler()->getImplementations('page_build') as $module) { - $function = $module . '_page_build'; - $function($page); - } + foreach (\Drupal::moduleHandler()->getImplementations('page_build') as $module) { + $function = $module . '_page_build'; + $function($page); } // Modules alter the $page as needed. Blocks are populated into regions like // 'sidebar_first', 'footer', etc. @@ -3591,11 +3583,11 @@ function drupal_prepare_page($page) { // cache, even though they should be. This happens because they're rendered // directly by the theme system. // @todo Remove this once https://drupal.org/node/1869476 lands. - if (!defined('MAINTENANCE_MODE') && theme_get_setting('features.main_menu') && count(menu_main_menu())) { + if (theme_get_setting('features.main_menu') && count(menu_main_menu())) { $main_links_source = _menu_get_links_source('main_links', 'main'); $page['page_top']['#cache']['tags']['menu'][$main_links_source] = $main_links_source; } - if (!defined('MAINTENANCE_MODE') && theme_get_setting('features.secondary_menu') && count(menu_secondary_menu())) { + if (theme_get_setting('features.secondary_menu') && count(menu_secondary_menu())) { $secondary_links_source = _menu_get_links_source('secondary_links', 'account'); $page['page_top']['#cache']['tags']['menu'][$secondary_links_source] = $secondary_links_source; } @@ -3603,7 +3595,7 @@ function drupal_prepare_page($page) { // If no module has taken care of the main content, add it to the page now. // This allows the site to still be usable even if no modules that // control page regions (for example, the Block module) are enabled. - if (!$main_content_display && !isset($page['content']['system_main'])) { + if (!$main_content_display) { $page['content']['system_main'] = drupal_set_page_content(); } diff --git a/core/lib/Drupal/Core/Page/DefaultHtmlPageRenderer.php b/core/lib/Drupal/Core/Page/DefaultHtmlPageRenderer.php index 4ce4ab2..4358ead 100644 --- a/core/lib/Drupal/Core/Page/DefaultHtmlPageRenderer.php +++ b/core/lib/Drupal/Core/Page/DefaultHtmlPageRenderer.php @@ -33,17 +33,31 @@ public function render(HtmlPage $page) { * Do NOT use this method in your code. This method will be removed as soon * as architecturally possible. * + * This is functionally very similar to DefaultHtmlFragmentRenderer::render() + * but with the following important differences: + * + * - drupal_prepare_page() and hook_page_build() cannot be invoked on the + * maintenance and install pages, since possibly enabled page layout/block + * modules would replace the main page content with configured region + * content. + * - This function composes a complete page render array including a page + * template theme suggestion (as opposed to the main page content only). + * - The render cache and cache tags is skipped. + * * @param array|string $main * A render array or string containing the main page content. * @param string $title * (optional) The page title. * @param string $theme - * (optional) The theme hook to use for rendering the page. The given value - * is appended with '_page' at this point, since ultimately this parameter - * will be converted into a theme template suggestion; i.e., #theme becomes - * 'page--$theme'. Defaults to 'maintenance'. + * (optional) The theme hook to use for rendering the page. Defaults to + * 'maintenance'. The given value will be appended with '_page' to compose + * the #theme property for #type 'page' currently; e.g., 'maintenance' + * becomes 'maintenance_page'. Ultimately this parameter will be converted + * into a page template theme suggestion; i.e., 'page__$theme'. * @param array $regions - * (optional) Additional region content to add to the page. + * (optional) Additional region content to add to the page. The given array + * is added to the page render array, so this parameter may also be used to + * pass e.g. the #show_messages property for #type 'page'. * * @return string * The rendered HTML page. @@ -51,27 +65,40 @@ public function render(HtmlPage $page) { * @internal */ public static function renderPage($main, $title = '', $theme = 'maintenance', array $regions = array()) { + // Automatically convert the main page content into a render array. if (!is_array($main)) { $main = array('#markup' => $main); } $page = new HtmlPage('', array(), $title); $page_array = array( '#type' => 'page', - // @todo Change this into "page__$theme" and rename templates into - // page--maintenance and page--install. + // @todo Change into theme suggestions "page__$theme". '#theme' => $theme . '_page', '#title' => $title, 'content' => array( 'system_main' => $main, ), ); + // Append region content. $page_array += $regions; + // Add default properties. $page_array += element_info('page'); + // hook_page_build() cannot be invoked on the maintenance and install pages, + // because the application is in an unknown or special state. + // In particular on the install page, invoking hook_page_build() directly + // after e.g. Block module has been installed would *replace* the installer + // output with the configured blocks of the installer theme (loaded from + // default configuration of the installation profile). + // Allow modules and themes to alter the page render array. + // This allows e.g. themes to attach custom libraries. \Drupal::moduleHandler()->alter('page', $page_array); + // @todo Move preparePage() before alter() above, so $page_array['#page'] is + // available in hook_page_alter(), so that HTML attributes can be altered. $page = \Drupal::service('html_fragment_renderer')->preparePage($page, $page_array); + $page->setBodyTop(drupal_render($page_array['page_top'])); $page->setBodyBottom(drupal_render($page_array['page_bottom'])); $page->setContent(drupal_render($page_array));