diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index db22e5f..35ab1d4 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -159,12 +159,12 @@ public function enable(array $theme_list) { * {@inheritdoc} */ public function disable(array $theme_list) { - // Don't disable the default theme. - if ($pos = array_search($this->configFactory->get('system.theme')->get('default'), $theme_list) !== FALSE) { - unset($theme_list[$pos]); - if (empty($theme_list)) { - return; - } + // Don't disable the default or admin themes. + $default_theme = \Drupal::config('system.theme')->get('default'); + $admin_theme = \Drupal::config('system.theme')->get('admin'); + $theme_list = array_diff($theme_list, array($default_theme, $admin_theme)); + if (empty($theme_list)) { + return; } $this->clearCssCache(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php index 638d8e5..76edbcd 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php @@ -279,4 +279,29 @@ function testPreprocessHtml() { $this->assertText('theme test page bottom markup', 'Modules are able to set the page bottom region.'); } + /** + * Test that themes can be disabled programmatically but admin theme and default theme can not. + */ + function testDisableTheme() { + // Enable Bartik, Seven and Stark. + \Drupal::service('theme_handler')->enable(array('bartik', 'seven', 'stark')); + + // Set Bartik as the default theme and Seven as the admin theme. + \Drupal::config('system.theme') + ->set('default', 'bartik') + ->set('admin', 'seven') + ->save(); + + $theme_list = array_keys(\Drupal::service('theme_handler')->listInfo()); + // Attempt to disable all themes. theme_disable() ensures that the default + // theme and the admin theme will not be disabled. + \Drupal::service('theme_handler')->disable($theme_list); + + $theme_list = \Drupal::service('theme_handler')->listInfo(); + + // Ensure Bartik and Seven are still enabled and Stark is disabled. + $this->assertTrue($theme_list['bartik']->status == 1, 'Default theme is enabled.'); + $this->assertTrue($theme_list['seven']->status == 1, 'Admin theme is enabled.'); + $this->assertTrue($theme_list['stark']->status == 0, 'Stark is disabled.'); + } }