Issue #2011128 by jsbalsera, aboros, Devin Carlson, mr.baileys, pplantinga: Theme_disable() can disable the wrong theme.

8.0.x
Alex Pott 2014-03-27 18:37:46 +01:00
parent ad6f3eac36
commit 8fa1fddaa8
2 changed files with 31 additions and 6 deletions

View File

@ -159,12 +159,12 @@ class ThemeHandler implements ThemeHandlerInterface {
* {@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();

View File

@ -279,4 +279,29 @@ class ThemeTest extends WebTestBase {
$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.');
}
}