Commit 678e6478 authored by catch's avatar catch
Browse files

task: #3618971 Use Admin theme in installer

By: quietone
By: catch
By: jurgenhaas
By: gábor hojtsy
By: acbramley
By: mherchel
By: godotislate
By: daffie
parent 1ed8ef5d
Loading
Loading
Loading
Loading
Loading
+1 −1
Changes for core/assets/scaffold/files/default.settings.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -642,7 +642,7 @@
 *
 * Note: This setting does not apply to installation and update pages.
 */
# $settings['maintenance_theme'] = 'claro';
# $settings['maintenance_theme'] = 'default_admin';

/**
 * PHP settings:
+1 −1
Changes for core/includes/install.core.inc: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -252,7 +252,7 @@ function install_state_defaults(): array {
    // An array of available installation profiles.
    'profiles' => [],
    // The name of the theme to use during installation.
    'theme' => 'claro',
    'theme' => InstallerKernel::INSTALL_THEME,
    // The server URL where the interface translation files can be downloaded.
    // Tokens in the pattern will be replaced by appropriate values for the
    // required translation file.
+7 −4
Changes for core/includes/theme.maintenance.inc: 7 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -13,9 +13,11 @@
 *
 * Used for site installs, updates and when the site is in maintenance mode.
 * It also applies when the database is unavailable or bootstrap was not
 * complete. Claro is always used for the initial install and update
 * complete. The admin theme is always used for the initial install and update
 * operations, but this can be overridden by setting a "maintenance_theme" key
 * in the $settings variable in settings.php.
 *
 * @see \Drupal\Core\Installer\InstallerKernel::INSTALL_THEME
 */
function _drupal_maintenance_theme(): void {
  // If the theme is already set, assume the others are set too, and do nothing.
@@ -34,7 +36,7 @@ function _drupal_maintenance_theme(): void {
      $custom_theme = $GLOBALS['install_state']['theme'];
    }
    else {
      $custom_theme = Settings::get('maintenance_theme', 'claro');
      $custom_theme = Settings::get('maintenance_theme', InstallerKernel::INSTALL_THEME);
    }
  }
  else {
@@ -54,8 +56,9 @@ function _drupal_maintenance_theme(): void {
    }
    if (!$custom_theme) {
      // We have been unable to identify the configured theme, so fall back to
      // a safe default. Claro is reasonably user friendly and fairly generic.
      $custom_theme = 'claro';
      // a safe default. The admin theme is reasonably user friendly and fairly
      // generic.
      $custom_theme = InstallerKernel::INSTALL_THEME;
    }
  }

+61 −10
Changes for core/lib/Drupal/Core/Installer/InstallerKernel.php: 61 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -13,6 +13,14 @@
 */
class InstallerKernel extends DrupalKernel {

  /**
   * The theme used for install, update and early maintenance pages.
   *
   * A distribution profile can request a different theme with the
   * distribution.install.theme key in its info file.
   */
  public const INSTALL_THEME = 'default_admin';

  /**
   * The extensions from the last container compilation.
   */
@@ -131,26 +139,69 @@ protected function getExtensions(): array {

    // Ensure that the System module is always available to the installer.
    $extensions['module']['system'] ??= 0;
    if ($profile = $this->installGetProfile()) {
    $profile = $this->installGetProfile();
    if ($profile) {
      $extensions['profile'] = $profile->getName();
      if (!isset($extensions['module'][$profile->getName()])) {
        $extensions['module'][$profile->getName()] = 1000;
      }
      $theme = $profile->info['distribution']['install']['theme'] ?? 'claro';
    }
    // Ensure that the install theme is always available to the installer.
    foreach ($this->getInstallThemes($profile) as $theme) {
      $extensions['theme'][$theme] ??= 0;
    }
    return $extensions;
  }

      if ($theme !== 'claro') {
        // Need to check for base themes.
        foreach ($this->getBaseThemes($profile, $theme) as $base_theme) {
          $extensions['theme'][$base_theme] ??= 0;
  /**
   * {@inheritdoc}
   */
  public function updateThemes(array $register_themes = []): void {
    if (static::installationAttempted()) {
      // Installing a profile or a recipe replaces the theme list with the
      // themes that were just installed, which do not include the install
      // theme. Theme hook implementations are collected from the
      // container.themes parameter, so dropping the install theme from the
      // list removes its hooks while it is still rendering the remaining
      // installer pages. Keep it registered until the installation is done.
      // @see \Drupal\Core\Hook\ThemeHookCollectorPass
      // @see _drupal_maintenance_theme()
      foreach ($this->getInstallThemes($this->installGetProfile()) as $theme) {
        if (isset($register_themes[$theme])) {
          continue;
        }
        $extension = $this->themeExtensions($theme);
        if ($extension) {
          $register_themes[$theme] = $extension;
        }
      }
    // Ensure that the default theme is always available to the installer.
    else {
      $extensions['theme']['claro'] ??= 0;
    }
    return $extensions;
    parent::updateThemes($register_themes);
  }

  /**
   * Gets the theme that renders installer pages, with its base themes.
   *
   * @param \Drupal\Core\Extension\Extension|false|null $profile
   *   The profile being installed, or NULL if none has been selected yet, or
   *   FALSE if the installation uses no profile.
   *
   * @return string[]
   *   The name of the install theme, followed by the names of its base themes.
   */
  private function getInstallThemes(null|false|Extension $profile): array {
    if (!$profile) {
      // Without a profile there is no distribution that could request another
      // theme.
      return [static::INSTALL_THEME];
    }
    $theme = $profile->info['distribution']['install']['theme'] ?? static::INSTALL_THEME;
    if ($theme === static::INSTALL_THEME) {
      // The default install theme declares "base theme: false", so scanning
      // the file system for base themes is not needed.
      return [$theme];
    }
    return array_merge([$theme], $this->getBaseThemes($profile, $theme));
  }

  /**
+1 −1
Changes for core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ public function processAttachments(AttachmentsInterface $response) {
          $extension = pathinfo($font['data'], PATHINFO_EXTENSION);
          $attached['html_head_link'][] = [
            [
              'href' => $this->fileUrlGenerator->generate($font['data'])->toString(),
              'href' => $this->fileUrlGenerator->generateString($font['data']),
              'rel' => 'preload',
              'as' => 'font',
              'type' => 'font/' . $extension,
Loading