diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index d335e65..c97aafc 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -684,6 +684,8 @@ function install_tasks($install_state) { 'display_name' => t('Install site'), 'type' => 'batch', ), + 'install_profile_themes' => array( + ), 'install_import_translations' => array( 'display_name' => t('Set up translations'), 'display' => $needs_translations, @@ -1837,6 +1839,41 @@ function install_profile_modules(&$install_state) { } /** + * Installs themes. + * + * This does not use a batch, since installing themes is faster than modules and + * because an installation profile typically enables 1-3 themes only (default + * theme, base theme, admin theme). + * + * @param $install_state + * An array of information about the current installation state. + */ +function install_profile_themes(&$install_state) { + $theme_handler = \Drupal::service('theme_handler'); + + // ThemeHandler::enable() resets the current list of themes. The theme used in + // the installer is not necessarily in the list of themes to install, so + // retain the current list. + $current_themes = $theme_handler->listInfo(); + + // Install the themes specified by the installation profile. + $themes = $install_state['profile_info']['themes']; + $theme_handler->enable($themes); + + // Set the default theme. + // @todo Merge system.module:enabled + system.theme:enabled + + // system.theme.disabled into core.extension, so that installation profiles + // are able to supply the default theme + admin theme configuration in + // system.theme (which cannot be provided by a profile currently, because it + // is force-replaced like system.module). + $theme_handler->setDefault($install_state['profile_info']['theme_default']); + + foreach ($current_themes as $theme) { + $theme_handler->addTheme($theme); + } +} + +/** * Imports languages via a batch process during installation. * * @param $install_state diff --git a/core/includes/install.inc b/core/includes/install.inc index 6f61503..506cd60 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -1095,6 +1095,8 @@ function install_profile_info($profile, $langcode = 'en') { // Set defaults for module info. $defaults = array( 'dependencies' => array(), + 'themes' => array('stark'), + 'theme_default' => 'stark', 'description' => '', 'version' => NULL, 'hidden' => FALSE, diff --git a/core/includes/theme.inc b/core/includes/theme.inc index ee03d18..3fb7fdd 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -101,10 +101,21 @@ function drupal_theme_initialize() { // Determine the active theme for the theme negotiator service. This includes // the default theme as well as really specific ones like the ajax base theme. $request = \Drupal::request(); - // @todo NULL is not actually supported by the theme system currently. - // 1. Change fallback to 'system'? - // 2. Is this fallback ever triggered to begin with? - $theme = \Drupal::service('theme.negotiator')->determineActiveTheme($request) ?: NULL; + $theme = \Drupal::service('theme.negotiator')->determineActiveTheme($request); + + // @todo Previously this used a fallback to Stark, but Stark may not be + // installed. Stark is essentially a "null" theme, which does not actually + // do anything. Technically the theme system should be able to operate with + // the raw/default module theme functions and templates only. + // _drupal_theme_initialize() loads the Twig engine at all times already; + // including it here should enable _theme() to work, but most likely + // _theme()'s code path is not prepared for "no theme, only default + // templates and default engine" yet. + if (!$theme || !isset($themes[$theme])) { + $theme = NULL; + include_once DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine'; + return; + } // Store the identifier for retrieving theme settings with. $theme_key = $theme; diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index 5fe0f07..064b573 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -125,6 +125,26 @@ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandle /** * {@inheritdoc} */ + public function getDefault() { + return $this->configFactory->get('system.theme')->get('default'); + } + + /** + * {@inheritdoc} + */ + public function setDefault($name) { + if (!isset($this->listInfo()[$name])) { + throw new \InvalidArgumentException("$name theme is not enabled."); + } + $this->configFactory->get('system.theme') + ->set('default', $name) + ->save(); + return $this; + } + + /** + * {@inheritdoc} + */ public function enable(array $theme_list, $enable_dependencies = TRUE) { $theme_config = $this->configFactory->get('system.theme'); $disabled_themes = $this->configFactory->get('system.theme.disabled'); @@ -275,6 +295,9 @@ public function listInfo() { return $this->list; } + /** + * {@inheritdoc} + */ public function addTheme(Extension $theme) { // @todo Remove this 100% unnecessary duplication of properties. foreach ($theme->info['stylesheets'] as $media => $stylesheets) { diff --git a/core/modules/system/lib/Drupal/system/Controller/SystemController.php b/core/modules/system/lib/Drupal/system/Controller/SystemController.php index 1f6cdb7..e322dda 100644 --- a/core/modules/system/lib/Drupal/system/Controller/SystemController.php +++ b/core/modules/system/lib/Drupal/system/Controller/SystemController.php @@ -189,7 +189,7 @@ public function systemAdminMenuBlockPage() { public function themesPage() { $config = $this->config('system.theme'); // Get current list of themes. - $themes = $this->themeHandler->listInfo(); + $themes = system_rebuild_theme_data(); uasort($themes, 'system_sort_modules_by_info_name'); $theme_default = $config->get('default'); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 21bfb28..920d90b 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -567,13 +567,6 @@ function system_requirements($phase) { * Implements hook_install(). */ function system_install() { - // Enable and set the default theme. Can't use theme_enable() this early in - // installation. - \Drupal::service('config.installer')->installDefaultConfig('theme', 'stark'); - \Drupal::config('system.theme') - ->set('default', 'stark') - ->save(); - // Populate the cron key state variable. $cron_key = Crypt::randomBytesBase64(55); \Drupal::state()->set('system.cron_key', $cron_key); diff --git a/core/profiles/standard/standard.info.yml b/core/profiles/standard/standard.info.yml index 26bef95..f3eedf8 100644 --- a/core/profiles/standard/standard.info.yml +++ b/core/profiles/standard/standard.info.yml @@ -35,3 +35,8 @@ dependencies: - views - views_ui - tour +themes: + - bartik + - seven +theme_default: + - bartik diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index bec1107..103009b 100644 --- a/core/profiles/standard/standard.install +++ b/core/profiles/standard/standard.install @@ -14,15 +14,6 @@ * @see system_install() */ function standard_install() { - // Enable Bartik theme and set it as default theme instead of Stark. - // @see system_install() - $default_theme = 'bartik'; - \Drupal::config('system.theme') - ->set('default', $default_theme) - ->save(); - theme_enable(array($default_theme)); - theme_disable(array('stark')); - // Set front page to "node". \Drupal::config('system.site')->set('page.front', 'node')->save(); @@ -78,7 +69,6 @@ function standard_install() { $shortcut->save(); // Enable the admin theme. - theme_enable(array('seven')); \Drupal::config('system.theme')->set('admin', 'seven')->save(); \Drupal::config('node.settings')->set('use_admin_theme', '1')->save(); }