From 90439b19e4d7c454f59a3bbbb70a80171aa7e59d Mon Sep 17 00:00:00 2001 From: JohnAlbin Date: Sat, 3 Dec 2011 02:52:06 +0800 Subject: [PATCH 1/3] Rename system_find_base_themes() to drupal_find_base_themes() --- core/includes/theme.inc | 41 +++++++++++++++++++++++++++++++++++ core/modules/system/system.module | 43 +------------------------------------ 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 902907a..79e0afc 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -778,6 +778,47 @@ function list_themes($refresh = FALSE) { } /** + * Find all the base themes for the specified theme. + * + * Themes can inherit templates and function implementations from earlier themes. + * + * @param $themes + * An array of available themes. + * @param $key + * The name of the theme whose base we are looking for. + * @param $used_keys + * A recursion parameter preventing endless loops. + * @return + * Returns an array of all of the theme's ancestors; the first element's value + * will be NULL if an error occurred. + */ +function drupal_find_base_themes($themes, $key, $used_keys = array()) { + $base_key = $themes[$key]->info['base theme']; + // Does the base theme exist? + if (!isset($themes[$base_key])) { + return array($base_key => NULL); + } + + $current_base_theme = array($base_key => $themes[$base_key]->info['name']); + + // Is the base theme itself a child of another theme? + if (isset($themes[$base_key]->info['base theme'])) { + // Do we already know the base themes of this theme? + if (isset($themes[$base_key]->base_themes)) { + return $themes[$base_key]->base_themes + $current_base_theme; + } + // Prevent loops. + if (!empty($used_keys[$base_key])) { + return array($base_key => NULL); + } + $used_keys[$base_key] = TRUE; + return drupal_find_base_themes($themes, $base_key, $used_keys) + $current_base_theme; + } + // If we get here, then this is our parent theme. + return $current_base_theme; +} + +/** * Generates themed output. * * All requests for themed output must go through this function. It examines diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 77d6ebf..2b55e04 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2549,7 +2549,7 @@ function _system_rebuild_theme_data() { // Now that we've established all our master themes, go back and fill in data // for subthemes. foreach ($sub_themes as $key) { - $themes[$key]->base_themes = system_find_base_themes($themes, $key); + $themes[$key]->base_themes = drupal_find_base_themes($themes, $key); // Don't proceed if there was a problem with the root base theme. if (!current($themes[$key]->base_themes)) { continue; @@ -2642,47 +2642,6 @@ function _system_default_theme_features() { } /** - * Find all the base themes for the specified theme. - * - * Themes can inherit templates and function implementations from earlier themes. - * - * @param $themes - * An array of available themes. - * @param $key - * The name of the theme whose base we are looking for. - * @param $used_keys - * A recursion parameter preventing endless loops. - * @return - * Returns an array of all of the theme's ancestors; the first element's value - * will be NULL if an error occurred. - */ -function system_find_base_themes($themes, $key, $used_keys = array()) { - $base_key = $themes[$key]->info['base theme']; - // Does the base theme exist? - if (!isset($themes[$base_key])) { - return array($base_key => NULL); - } - - $current_base_theme = array($base_key => $themes[$base_key]->info['name']); - - // Is the base theme itself a child of another theme? - if (isset($themes[$base_key]->info['base theme'])) { - // Do we already know the base themes of this theme? - if (isset($themes[$base_key]->base_themes)) { - return $themes[$base_key]->base_themes + $current_base_theme; - } - // Prevent loops. - if (!empty($used_keys[$base_key])) { - return array($base_key => NULL); - } - $used_keys[$base_key] = TRUE; - return system_find_base_themes($themes, $base_key, $used_keys) + $current_base_theme; - } - // If we get here, then this is our parent theme. - return $current_base_theme; -} - -/** * Get a list of available regions from a specified theme. * * @param $theme_key -- 1.7.7.4 From 8105826551322ee381c7f3c9014740826f8a8d96 Mon Sep 17 00:00:00 2001 From: JohnAlbin Date: Sat, 3 Dec 2011 02:52:50 +0800 Subject: [PATCH 2/3] Make system_list() cache base_themes and sub_themes arrays for themes --- core/includes/module.inc | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-) diff --git a/core/includes/module.inc b/core/includes/module.inc index 221ad60..31a476c 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -178,6 +178,21 @@ function system_list($type) { $lists['filepaths'][] = array('type' => $record->type, 'name' => $record->name, 'filepath' => $record->filename); } } + foreach ($lists['theme'] as $key => $theme) { + if (!empty($theme->info['base theme'])) { + // Make a list of the theme's base themes. + $lists['theme'][$key]->base_themes = drupal_find_base_themes($lists['theme'], $key); + // Don't proceed if there was a problem with the root base theme. + if (!current($lists['theme'][$key]->base_themes)) { + continue; + } + // Make a list of the theme's sub-themes. + $base_key = key($lists['theme'][$key]->base_themes); + foreach (array_keys($lists['theme'][$key]->base_themes) as $base_theme) { + $lists['theme'][$base_theme]->sub_themes[$key] = $lists['theme'][$key]->info['name']; + } + } + } cache('bootstrap')->set('system_list', $lists); } // To avoid a separate database lookup for the filepath, prime the -- 1.7.7.4 From d1d424a1db06df49e8f48b82549be6cb81161796 Mon Sep 17 00:00:00 2001 From: JohnAlbin Date: Sat, 3 Dec 2011 02:53:08 +0800 Subject: [PATCH 3/3] Add tests --- core/modules/simpletest/tests/theme.test | 26 ++++++++++++++++++++ core/themes/tests/test_theme/test_theme.info | 2 + .../update_test_basetheme.info | 3 ++ .../update_test_subtheme/update_test_subtheme.info | 2 + 4 files changed, 33 insertions(+), 0 deletions(-) diff --git a/core/modules/simpletest/tests/theme.test b/core/modules/simpletest/tests/theme.test index 7968cf7..bea6f85 100644 --- a/core/modules/simpletest/tests/theme.test +++ b/core/modules/simpletest/tests/theme.test @@ -110,6 +110,32 @@ class ThemeUnitTest extends DrupalWebTestCase { $this->drupalGet('theme-test/template-test'); $this->assertText('Success: Template overridden.', t('Template overridden by defined \'template\' filename.')); } + + /** + * Test the list_themes() function. + */ + function testListThemes() { + $themes = list_themes(); + // Check if drupal_theme_access() retrieves enabled themes properly from list_themes(). + $this->assertTrue(drupal_theme_access('test_theme'), t('Enabled theme detected')); + // Check if list_themes() returns disabled themes. + $this->assertTrue(array_key_exists('update_test_basetheme', $themes), t('Disabled theme detected')); + // Check for base theme and subtheme lists. + $base_theme_list = array('update_test_basetheme' => 'Update test base theme'); + $sub_theme_list = array('update_test_subtheme' => 'Update test subtheme'); + $this->assertIdentical($themes['update_test_basetheme']->sub_themes, $sub_theme_list, t('Base theme\'s object includes list of subthemes.')); + $this->assertIdentical($themes['update_test_subtheme']->base_themes, $base_theme_list, t('Subtheme\'s object includes list of base themes.')); + } + + /** + * Test the theme_get_setting() function. + */ + function testThemeGetSetting() { + $GLOBALS['theme_key'] = 'test_theme'; + $this->assertIdentical(theme_get_setting('theme_test_setting'), 'default value', t('theme_get_setting() uses the default theme automatically.')); + $this->assertNotEqual(theme_get_setting('subtheme_override', 'update_test_basetheme'), theme_get_setting('subtheme_override', 'update_test_subtheme'), t('Base theme\'s default settings values can be overridden by subtheme.')); + $this->assertIdentical(theme_get_setting('basetheme_only', 'update_test_subtheme'), 'base theme value', t('Base theme\'s default settings values are inherited by subtheme.')); + } } /** diff --git a/core/themes/tests/test_theme/test_theme.info b/core/themes/tests/test_theme/test_theme.info index c32fe57..b5d1bfc 100644 --- a/core/themes/tests/test_theme/test_theme.info +++ b/core/themes/tests/test_theme/test_theme.info @@ -14,3 +14,5 @@ hidden = TRUE ; version from being loaded, and that errors aren't caused by the lack of this ; file within the theme folder. stylesheets[all][] = system.base.css + +settings[theme_test_setting] = default value diff --git a/core/themes/tests/update_test_basetheme/update_test_basetheme.info b/core/themes/tests/update_test_basetheme/update_test_basetheme.info index c8550b5..00d6dc5 100644 --- a/core/themes/tests/update_test_basetheme/update_test_basetheme.info +++ b/core/themes/tests/update_test_basetheme/update_test_basetheme.info @@ -2,3 +2,6 @@ name = Update test base theme description = Test theme which acts as a base theme for other test subthemes. core = 8.x hidden = TRUE + +settings[basetheme_only] = base theme value +settings[subtheme_override] = base theme value diff --git a/core/themes/tests/update_test_subtheme/update_test_subtheme.info b/core/themes/tests/update_test_subtheme/update_test_subtheme.info index c783dc2..283889d 100644 --- a/core/themes/tests/update_test_subtheme/update_test_subtheme.info +++ b/core/themes/tests/update_test_subtheme/update_test_subtheme.info @@ -3,3 +3,5 @@ description = Test theme which uses update_test_basetheme as the base theme. core = 8.x base theme = update_test_basetheme hidden = TRUE + +settings[subtheme_override] = subtheme value -- 1.7.7.4