Commit 8fa1fdda authored by alexpott's avatar alexpott

Issue #2011128 by jsbalsera, aboros, Devin Carlson, mr.baileys, pplantinga:...

Issue #2011128 by jsbalsera, aboros, Devin Carlson, mr.baileys, pplantinga: Theme_disable() can disable the wrong theme.
parent ad6f3eac
......@@ -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();
......
......@@ -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.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment