diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 7962015..7cf7932 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -1599,8 +1599,10 @@ function _drupal_bootstrap_configuration() { Unicode::check(); // Set the Drupal custom error handler. (requires \Drupal::config()) - set_error_handler('_drupal_error_handler'); - set_exception_handler('_drupal_exception_handler'); + if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE !== 'install') { + set_error_handler('_drupal_error_handler'); + set_exception_handler('_drupal_exception_handler'); + } // Redirect the user to the installation script if Drupal has not been // installed yet (i.e., if no $databases array has been defined in the diff --git a/core/includes/common.inc b/core/includes/common.inc index d18c0c1..b68d6d0 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3635,6 +3635,12 @@ 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(). foreach (\Drupal::moduleHandler()->getImplementations('page_build') as $module) { @@ -3662,7 +3668,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) { + if (!$main_content_display && !isset($page['content']['system_main'])) { $page['content']['system_main'] = drupal_set_page_content(); } diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 8d27e08..50d78f4 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -14,6 +14,7 @@ use Drupal\Core\Installer\Exception\NoProfilesException; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManager; +use Drupal\Core\Page\HtmlPage; use Drupal\Core\StringTranslation\Translator\FileTranslation; use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\Core\DependencyInjection\ContainerBuilder; @@ -299,6 +300,7 @@ function install_begin_request(&$install_state) { require_once __DIR__ . '/form.inc'; require_once __DIR__ . '/batch.inc'; require_once __DIR__ . '/ajax.inc'; + require_once __DIR__ . '/menu.inc'; // Load module basics (needed for hook invokes). include_once __DIR__ . '/module.inc'; @@ -349,6 +351,14 @@ function install_begin_request(&$install_state) { if (!$install_state['base_system_verified']) { $environment = 'install'; $GLOBALS['conf']['container_service_providers']['InstallerServiceProvider'] = 'Drupal\Core\Installer\InstallerServiceProvider'; + + // Various services need a database connection. Supply one. + if (!$install_state['database_verified']) { + Database::addConnectionInfo('install', 'default', array( + 'driver' => 'sqlite', + 'database' => ':memory:', + )); + } } else { $environment = 'prod'; @@ -399,12 +409,17 @@ function install_begin_request(&$install_state) { // Override the module list with a minimal set of modules. $module_handler = \Drupal::moduleHandler(); - $module_list = $module_handler->getModuleList(); - if (!$module_handler->moduleExists('system')) { - $module_list['system'] = 'core/modules/system/system.module'; - } - if ($profile && !$module_handler->moduleExists($profile)) { + $original_module_list = $module_handler->getModuleList(); + $module_list = array(); + $module_list['system'] = 'core/modules/system/system.module'; + system_register('module', 'system', $module_list['system']); + if (isset($original_module_list['user'])) { + $module_list['user'] = 'core/modules/user/user.module'; + system_register('module', 'user', $module_list['user']); + } + if ($profile) { $module_list[$profile] = $install_state['profiles'][$profile]->uri; + system_register('profile', $profile, $module_list[$profile]); } $module_handler->setModuleList($module_list); // After setting up a custom and finite module list in a custom low-level @@ -900,6 +915,15 @@ function install_display_output($output, $install_state) { ); drupal_add_html_head($noindex_meta_tag, 'install_meta_robots'); + $install_page = array( + '#type' => 'page', + '#theme' => 'install_page', + '#title' => $output['#title'], + 'content' => array( + 'system_main' => $output, + ), + ); + // Only show the task list if there is an active task; otherwise, the page // request has ended before tasks have even been started, so there is nothing // meaningful to show. @@ -913,20 +937,20 @@ function install_display_output($output, $install_state) { '#active' => $active_task, '#variant' => 'install', ); - drupal_add_region_content('sidebar_first', drupal_render($task_list)); + $install_page['sidebar_first'] = $task_list; } - $install_page = array( - '#theme' => 'install_page', - // $output has to be rendered here, because the install page template is not - // wrapped into the html template, which means that any #attached libraries - // in $output will not be loaded, because the wrapping HTML has been printed - // already. - '#content' => drupal_render($output), - ); - if (isset($output['#title'])) { - $install_page['#page']['#title'] = $output['#title']; - } - print drupal_render($install_page); + + // @see \Drupal\Core\Page\DefaultHtmlFragmentRenderer::render() + // @see \Drupal\system\Controller\BatchController::render() + $page = new HtmlPage('', array(), $output['#title']); + $page_array = drupal_prepare_page($install_page); + + $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)); + + print \Drupal::service('html_page_renderer')->render($page); exit; } diff --git a/core/includes/theme.inc b/core/includes/theme.inc index cfd8427..ab2f37b 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1967,9 +1967,6 @@ function template_preprocess_html(&$variables) { } } - // Initializes attributes which are specific to the html and body elements. - $variables['html_attributes'] = new Attribute; - // HTML element attributes. $language_interface = \Drupal::service('language_manager')->getCurrentLanguage(); $variables['html_attributes']['lang'] = $language_interface->id; @@ -2213,12 +2210,6 @@ function theme_get_suggestions($args, $base, $delimiter = '__') { * * Default template: maintenance-page.html.twig. * - * The variables array generated here is a mirror of - * template_preprocess_page(). This preprocessor will run its course when - * theme_maintenance_page() is invoked. An alternate template file of - * maintenance-page--offline.html.twig can be used when the database is offline - * to hide errors and completely replace the content. - * * @param array $variables * An associative array containing: * - content - An array of page content. @@ -2226,117 +2217,28 @@ function theme_get_suggestions($args, $base, $delimiter = '__') { * @see system_page_build() */ function template_preprocess_maintenance_page(&$variables) { - $language_interface = \Drupal::languageManager()->getCurrentLanguage(); - - // Initializes attributes which are specific to the html element. - $variables['html_attributes'] = new Attribute; - - // HTML element attributes. - $variables['html_attributes']['lang'] = $language_interface->id; - $variables['html_attributes']['dir'] = $language_interface->direction ? 'rtl' : 'ltr'; - - // Add favicon - if (theme_get_setting('features.favicon')) { - $favicon = theme_get_setting('favicon.url'); - $type = theme_get_setting('favicon.mimetype'); - $build['#attached']['drupal_add_html_head_link'][][] = array( - 'rel' => 'shortcut icon', - 'href' => UrlHelper::stripDangerousProtocols($favicon), - 'type' => $type, - ); - drupal_render($build); - } - - foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) { - if (!isset($variables[$region_key])) { - $variables[$region_key] = array(); - } - // Append region content set with drupal_add_region_content() as markup. - if ($region_content = drupal_get_region_content($region_key)) { - $variables[$region_key][]['#markup'] = $region_content; - } - } - - // Setup layout variable. - $variables['layout'] = 'none'; - if (!empty($variables['sidebar_first'])) { - $variables['layout'] = 'first'; - } - if (!empty($variables['sidebar_second'])) { - $variables['layout'] = ($variables['layout'] == 'first') ? 'both' : 'second'; - } - - $site_config = \Drupal::config('system.site'); - $site_name = $site_config->get('name'); - $site_slogan = $site_config->get('slogan'); - - // Construct the page title. - if (isset($variables['page']['#title'])) { - $head_title = array( - 'title' => strip_tags($variables['page']['#title']), - 'name' => String::checkPlain($site_config->get('name')), - ); - } - else { - $head_title = array('name' => String::checkPlain($site_name)); - if ($site_slogan) { - $head_title['slogan'] = strip_tags(filter_xss_admin($site_slogan)); - } - } + // @todo Rename the templates to page--maintenance + page--install. + template_preprocess_page($variables); - // These are usually added from system_page_build() except maintenance.css. - // When the database is inactive it's not called so we add it here. - $default_css['library'][] = 'core/normalize'; - $default_css['library'][] = 'system/maintenance'; - $attached = array('#attached' => $default_css); - drupal_render($attached); - $variables['messages'] = array( - '#theme' => 'status_messages', - '#access' => $variables['show_messages'], - ); - - $variables['head_title_array'] = $head_title; - $variables['head_title'] = implode(' | ', $head_title); - $variables['front_page'] = url(); - $variables['help'] = ''; - $variables['language'] = $language_interface; - $variables['logo'] = theme_get_setting('logo.url'); - $variables['site_name'] = (theme_get_setting('features.name') ? String::checkPlain($site_name) : ''); - $variables['site_slogan'] = (theme_get_setting('features.slogan') ? filter_xss_admin($site_slogan) : ''); + $page_object = $variables['page']['#page']; + $attributes = $page_object->getBodyAttributes(); + $classes = $attributes['class']; - // Compile a list of classes that are going to be applied to the body element. - $variables['attributes']['class'][] = 'maintenance-page'; - $variables['attributes']['class'][] = 'in-maintenance'; + $classes[] = 'maintenance-page'; + $classes[] = 'in-maintenance'; if (isset($variables['db_is_active']) && !$variables['db_is_active']) { - $variables['attributes']['class'][] = 'db-offline'; - } - if ($variables['layout'] == 'both') { - $variables['attributes']['class'][] = 'two-sidebars'; - } - elseif ($variables['layout'] == 'none') { - $variables['attributes']['class'][] = 'no-sidebars'; - } - else { - $variables['attributes']['class'][] = 'one-sidebar'; - $variables['attributes']['class'][] = 'sidebar-' . $variables['layout']; + $classes[] = 'db-offline'; } + $attributes['class'] = $classes; - $variables['head'] = drupal_get_html_head(); - - // While this code is used in the installer, the language module may not be - // enabled yet (even maybe no database set up yet), but an RTL language - // selected should result in RTL stylesheets loaded properly already. - $css = _drupal_add_css(); - include_once DRUPAL_ROOT . '/core/modules/language/language.module'; - // Wrapping drupal_get_css() and drupal_get_js() in an object so they can - // be called when printed. - $variables['styles'] = new RenderWrapper('drupal_get_css', array($css)); - $variables['scripts'] = new RenderWrapper('drupal_get_js'); - - // Allow the page to define a title. - if (isset($variables['page']['#title'])) { - $variables['title'] = $variables['page']['#title']; - } + $attached = array( + '#attached' => array( + 'library' => array( + 'system/maintenance', + ), + ), + ); + drupal_render($attached); } /** @@ -2357,7 +2259,15 @@ function template_preprocess_maintenance_page(&$variables) { */ function template_preprocess_install_page(&$variables) { template_preprocess_maintenance_page($variables); - $variables['attributes']['class'][] = 'install-page'; + + $page_object = $variables['page']['#page']; + $attributes = $page_object->getBodyAttributes(); + $classes = $attributes['class']; + + $classes[] = 'install-page'; + + $attributes['class'] = $classes; + // Override the site name that is displayed on the page, since Drupal is // still in the process of being installed. $distribution_name = String::checkPlain(drupal_install_profile_distribution_name()); @@ -2472,11 +2382,11 @@ function drupal_common_theme() { ), // From theme.maintenance.inc. 'maintenance_page' => array( - 'variables' => array('content' => NULL, 'show_messages' => TRUE, 'page' => array()), + 'render element' => 'page', 'template' => 'maintenance-page', ), 'install_page' => array( - 'variables' => array('content' => NULL, 'show_messages' => TRUE, 'page' => array()), + 'render element' => 'page', 'template' => 'install-page', ), 'task_list' => array( diff --git a/core/includes/theme.maintenance.inc b/core/includes/theme.maintenance.inc index 429b932..903c63f 100644 --- a/core/includes/theme.maintenance.inc +++ b/core/includes/theme.maintenance.inc @@ -30,6 +30,7 @@ function _drupal_maintenance_theme() { require_once __DIR__ . '/unicode.inc'; require_once __DIR__ . '/file.inc'; require_once __DIR__ . '/module.inc'; + require_once __DIR__ . '/database.inc'; Unicode::check(); // Install and update pages are treated differently to prevent theming overrides. @@ -42,13 +43,6 @@ function _drupal_maintenance_theme() { } } else { - // The bootstrap was not complete. So we are operating in a crippled - // environment, we need to bootstrap just enough to allow hook invocations - // to work. See _drupal_log_error(). - if (!class_exists('Drupal\Core\Database\Database', FALSE)) { - require_once __DIR__ . '/database.inc'; - } - // Use the maintenance theme if specified, otherwise attempt to use the // default site theme. try { diff --git a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php index 2389a62..26b1d7d 100644 --- a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php +++ b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Installer; +use Drupal\Core\Database\Database; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceProviderInterface; use Drupal\Core\DependencyInjection\ServiceModifierInterface; @@ -66,6 +67,8 @@ public function alter(ContainerBuilder $container) { // throws an exception upon trying to load a non-existing file. $container->get('config.factory')->setOverrideState(FALSE); + $container->set('database', Database::getConnection('default', 'install')); + // No service may persist when the early installer kernel is rebooted into // the production environment. // @todo The DrupalKernel reboot performed by drupal_install_system() is diff --git a/core/modules/system/templates/install-page.html.twig b/core/modules/system/templates/install-page.html.twig index 031013e..45f37d2 100644 --- a/core/modules/system/templates/install-page.html.twig +++ b/core/modules/system/templates/install-page.html.twig @@ -11,56 +11,45 @@ * @ingroup themeable */ #} - - - - {{ head }} - {{ head_title }} - {{ styles }} - {{ scripts }} - - +
-
- -
- {% if site_name or site_slogan %} -
- {% if site_name %} -

{{ site_name }}

- {% endif %} - {% if site_slogan %} -
{{ site_slogan }}
- {% endif %} -
{# /.name-and-slogan #} - {% endif %} -
- -
- {% if title %} -

{{ title }}

- {% endif %} - {{ messages }} - {{ content }} -
- - {% if sidebar_first %} - {# /.l-sidebar-first #} +
+ {% if site_name or site_slogan %} +
+ {% if site_name %} +

{{ site_name }}

+ {% endif %} + {% if site_slogan %} +
{{ site_slogan }}
+ {% endif %} +
{# /.name-and-slogan #} {% endif %} +
- {% if sidebar_second %} - {# /.l-sidebar-second #} +
+ {% if title %} +

{{ title }}

{% endif %} + {{ messages }} + {{ page.content }} +
- {% if footer %} -
- {{ footer }} -
- {% endif %} + {% if page.sidebar_first %} + {# /.l-sidebar-first #} + {% endif %} + + {% if page.sidebar_second %} + {# /.l-sidebar-second #} + {% endif %} + + {% if page.footer %} +
+ {{ page.footer }} +
+ {% endif %} - - +
{# /.l-container #} diff --git a/core/themes/seven/seven.theme b/core/themes/seven/seven.theme index 6f5ce6b..9c47478 100644 --- a/core/themes/seven/seven.theme +++ b/core/themes/seven/seven.theme @@ -269,8 +269,11 @@ function seven_element_info_alter(&$type) { * Implements hook_preprocess_install_page(). */ function seven_preprocess_install_page(&$variables) { - $variables['styles'] = new RenderWrapper('drupal_get_css'); - $variables['scripts'] = new RenderWrapper('drupal_get_js'); + $page_object = $variables['page']['#page']; + $attributes = $page_object->getHtmlAttributes(); + $classes = $attributes['class']; + $classes[] = 'install-background'; + $attributes['class'] = $classes; // Normally we could attach libraries via hook_page_alter(), but when the // database is inactive it's not called so we add them here. diff --git a/core/themes/seven/templates/install-page.html.twig b/core/themes/seven/templates/install-page.html.twig index 81ddece..85fc7e4 100644 --- a/core/themes/seven/templates/install-page.html.twig +++ b/core/themes/seven/templates/install-page.html.twig @@ -12,16 +12,6 @@ * @ingroup themeable */ #} - - - - {{ head }} - {{ head_title }} - {{ styles }} - {{ scripts }} - - -
@@ -37,9 +27,9 @@ {% endif %}
- {% if sidebar_first %} + {% if page.sidebar_first %} {# /.l-sidebar-first #} {% endif %} @@ -48,22 +38,19 @@

{{ title }}

{% endif %} {{ messages }} - {{ content }} + {{ page.content }} - {% if sidebar_second %} + {% if page.sidebar_second %} {# /.l-sidebar-second #} {% endif %} - {% if footer %} + {% if page.footer %} {% endif %}
{# /.l-container #} - - -