Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.1017 diff -u -p -r1.1017 common.inc --- includes/common.inc 13 Oct 2009 21:16:42 -0000 1.1017 +++ includes/common.inc 14 Oct 2009 00:18:04 -0000 @@ -4308,6 +4308,21 @@ function drupal_alter($type, &$data, &$c $function = $module . '_' . $hook; $function($data, $context1, $context2); } + // Allow the theme to alter variables after the theme system has been + // initialized. + if (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL) { + global $theme, $base_theme; + $themes = array($theme); + foreach ($base_theme as $base) { + $themes[] = $base->name; + } + foreach ($themes as $theme) { + $function = $theme . '_' . $hook; + if (function_exists($function)) { + $function($data, $context1, $context2); + } + } + } } /** Index: includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.534 diff -u -p -r1.534 theme.inc --- includes/theme.inc 13 Oct 2009 05:26:57 -0000 1.534 +++ includes/theme.inc 14 Oct 2009 00:13:32 -0000 @@ -55,7 +55,7 @@ function drupal_theme_access($theme) { * Initialize the theme system by loading the theme. */ function drupal_theme_initialize() { - global $theme, $user, $theme_key; + global $theme, $user, $theme_key, $base_theme; // If $theme is already set, assume the others are set, too, and do nothing if (isset($theme)) { @@ -84,7 +84,8 @@ function drupal_theme_initialize() { $base_theme[] = $new_base_theme = $themes[$themes[$ancestor]->base_theme]; $ancestor = $themes[$ancestor]->base_theme; } - _drupal_theme_initialize($themes[$theme], array_reverse($base_theme)); + $base_theme = array_reverse($base_theme); + _drupal_theme_initialize($themes[$theme], $base_theme); } /** Index: includes/theme.maintenance.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.maintenance.inc,v retrieving revision 1.42 diff -u -p -r1.42 theme.maintenance.inc --- includes/theme.maintenance.inc 9 Oct 2009 00:59:54 -0000 1.42 +++ includes/theme.maintenance.inc 14 Oct 2009 00:13:32 -0000 @@ -15,7 +15,7 @@ * $conf variable in order to change the maintenance theme. */ function _drupal_maintenance_theme() { - global $theme, $theme_key; + global $theme, $theme_key, $base_theme; // If $theme is already set, assume the others are set too, and do nothing. if (isset($theme)) { @@ -30,6 +30,7 @@ function _drupal_maintenance_theme() { require_once DRUPAL_ROOT . '/includes/module.inc'; require_once DRUPAL_ROOT . '/includes/database/database.inc'; unicode_check(); + $base_theme = array(); // Install and update pages are treated differently to prevent theming overrides. if (defined('MAINTENANCE_MODE') && (MAINTENANCE_MODE == 'install' || MAINTENANCE_MODE == 'update')) { Index: modules/simpletest/tests/common.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v retrieving revision 1.84 diff -u -p -r1.84 common.test --- modules/simpletest/tests/common.test 13 Oct 2009 16:38:43 -0000 1.84 +++ modules/simpletest/tests/common.test 14 Oct 2009 00:27:13 -0000 @@ -29,24 +29,24 @@ class DrupalAlterTestCase extends Drupal // Verify alteration of a single argument. $array_copy = $array; - $array_expected = array('foo' => 'Drupal'); + $array_expected = array('foo' => 'Drupal theme'); drupal_alter('drupal_alter', $array_copy); $this->assertEqual($array_copy, $array_expected, t('Single array was altered.')); $object_copy = clone $object; $object_expected = clone $object; - $object_expected->foo = 'Drupal'; + $object_expected->foo = 'Drupal theme'; drupal_alter('drupal_alter', $object_copy); $this->assertEqual($object_copy, $object_expected, t('Single object was altered.')); // Verify alteration of multiple arguments. $array_copy = $array; - $array_expected = array('foo' => 'Drupal'); + $array_expected = array('foo' => 'Drupal theme'); $object_copy = clone $object; $object_expected = clone $object; - $object_expected->foo = 'Drupal'; + $object_expected->foo = 'Drupal theme'; $array2_copy = $array; - $array2_expected = array('foo' => 'Drupal'); + $array2_expected = array('foo' => 'Drupal theme'); drupal_alter('drupal_alter', $array_copy, $object_copy, $array2_copy); $this->assertEqual($array_copy, $array_expected, t('First argument to drupal_alter() was altered.')); $this->assertEqual($object_copy, $object_expected, t('Second argument to drupal_alter() was altered.')); Index: modules/simpletest/tests/common_test.module =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common_test.module,v retrieving revision 1.5 diff -u -p -r1.5 common_test.module --- modules/simpletest/tests/common_test.module 13 Oct 2009 16:38:43 -0000 1.5 +++ modules/simpletest/tests/common_test.module 14 Oct 2009 00:29:58 -0000 @@ -101,6 +101,40 @@ function common_test_drupal_alter_alter( } /** + * Implement hook_TYPE_alter() on behalf of Garland theme. + * + * Same as common_test_drupal_alter_alter(), but here, we verify that themes + * can also alter and come last. + */ +function garland_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) { + // Alter first argument. + if (is_array($data)) { + $data['foo'] .= ' theme'; + } + elseif (is_object($data)) { + $data->foo .= ' theme'; + } + // Alter second argument, if present. + if (isset($arg2)) { + if (is_array($arg2)) { + $arg2['foo'] .= ' theme'; + } + elseif (is_object($arg2)) { + $arg2->foo .= ' theme'; + } + } + // Try to alter third argument, if present. + if (isset($arg3)) { + if (is_array($arg3)) { + $arg3['foo'] .= ' theme'; + } + elseif (is_object($arg3)) { + $arg3->foo .= ' theme'; + } + } +} + +/** * Implement hook_theme(). */ function common_test_theme() {