Issue #2011128 by jsbalsera, aboros, Devin Carlson, mr.baileys, pplantinga: Theme_disable() can disable the wrong theme.
parent
ad6f3eac36
commit
8fa1fddaa8
|
@ -159,12 +159,12 @@ class ThemeHandler implements ThemeHandlerInterface {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function disable(array $theme_list) {
|
public function disable(array $theme_list) {
|
||||||
// Don't disable the default theme.
|
// Don't disable the default or admin themes.
|
||||||
if ($pos = array_search($this->configFactory->get('system.theme')->get('default'), $theme_list) !== FALSE) {
|
$default_theme = \Drupal::config('system.theme')->get('default');
|
||||||
unset($theme_list[$pos]);
|
$admin_theme = \Drupal::config('system.theme')->get('admin');
|
||||||
if (empty($theme_list)) {
|
$theme_list = array_diff($theme_list, array($default_theme, $admin_theme));
|
||||||
return;
|
if (empty($theme_list)) {
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->clearCssCache();
|
$this->clearCssCache();
|
||||||
|
|
|
@ -279,4 +279,29 @@ class ThemeTest extends WebTestBase {
|
||||||
$this->assertText('theme test page bottom markup', 'Modules are able to set the page bottom region.');
|
$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.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue