diff --git includes/bootstrap.inc includes/bootstrap.inc index 4cbfc3f..5a75dbe 100644 --- includes/bootstrap.inc +++ includes/bootstrap.inc @@ -773,6 +773,129 @@ function variable_initialize($conf = array()) { } /** + * Get the name of the currently active install profile. + * + * When this function is called during Drupal's initial installation process, + * the name of the profile that's about to be installed is stored in the global + * installation state. At all other times, the standard Drupal systems variable + * table contains the name of the current profile, and we can call variable_get() + * to determine what one is active. + * + * @return $profile + * The name of the install profile. + */ +function drupal_get_profile() { + global $install_state; + + if (isset($install_state['parameters']['profile'])) { + $profile = $install_state['parameters']['profile']; + } + else { + $profile = variable_get('install_profile', 'standard'); + } + + return $profile; +} + +/** + * Add directories to search for system object files (modules, themes, etc.). + * + * This function is used to add directories to be searched when we build + * the system table. This function also manages the order of precedence + * of modules / themes found in these directories. + * + * There are three main levels of precedence, namely 'site' modules override + * 'profile' modules which override 'system' modules. You are also able to + * add a directory before or after any of these levels by prepending the + * scope variable with 'before:' or 'after:'. + * + * For instance, if you want to add a directory to search for additional modules + * that should override modules in your /sites/$sitename/ directory, you can + * use : + * drupal_add_system_directory('after:site', 'custom/path'); + * + * If no additional paths have been configured, the default directories are : + * + * system - $directory + * profile - profiles/$profilename/$directory + * before:site - sites/all/$directory + * site - sites/$sitename/$directory + * + * @param $scope + * The scope of the include path to be added. May be one of the following: + * - before:system + * - system + * - after:system + * - before:profile + * - profile + * - after:profile + * - before:site + * - site + * - after:site + * - host_profile + * + * @param $directory + * The relative path to be added. + * + * @return + * If $scope is null, return the list of directories. + */ +function drupal_add_system_directory($scope = null, $directory = null) { + static $search_dirs = array(); + + // Pre-load the directory array with the know directory scopes. + if (!sizeof($search_dirs)) { + // Drupal base system directories. + $search_dirs['before:system'] = array(); + $search_dirs['system'] = array('.'); + $search_dirs['after:system'] = array(); + + // The 'profiles' directory contains pristine collections of modules and + // themes as organized by a distribution. It is pristine in the same way + // that /modules is pristine for core; users should avoid changing anything + // there in favor of sites/all or sites/ directories. + $search_dirs['before:profile'] = array(); + $search_dirs['profile'] = array(); + $search_dirs['after:profile'] = array(); + + // Always search sites/all/* as well as the global directories + $search_dirs['before:site'] = array('sites/all'); + // The configuraton path. + $search_dirs['site'] = array(); + $search_dirs['after:site'] = array(); + } + + // Return the entire list of directories. + if (is_null($scope) && is_null($directory)) { + return $search_dirs; + } + + if (!is_null($directory) && !is_null($scope)) { + $search_dirs[$scope][] = $directory; + } + + if (array_key_exists($scope, $search_dirs)) { + return $search_dirs[$scope]; + } + + return FALSE; +} + +/** + * Returns directories searched for system object files (modules, themes etc.). + * + * This function is used to return the directories that have been added with + * drupal_add_system_directory(). + * + * @return + * Array containing directory paths. + */ +function drupal_get_system_directory() { + return drupal_add_system_directory(); +} + + +/** * Returns a persistent variable. * * Case-sensitivity of the variable_* functions depends on the database @@ -2089,6 +2212,9 @@ function _drupal_bootstrap_configuration() { timer_start('page'); // Initialize the configuration, including variables from settings.php. drupal_settings_initialize(); + + // Add the config path to the search path. + drupal_add_system_directory('site', conf_path()); } /** @@ -2220,6 +2346,10 @@ function _drupal_bootstrap_variables() { // Load variables from the database, but do not overwrite variables set in settings.php. $conf = variable_initialize(isset($conf) ? $conf : array()); + + // Add the installation profile to the system directories. + drupal_add_system_directory('profile', "profiles/" . drupal_get_profile()); + // Load bootstrap modules. require_once DRUPAL_ROOT . '/includes/module.inc'; module_load_all(TRUE); diff --git includes/common.inc includes/common.inc index 5a7e340..f03fb6b 100644 --- includes/common.inc +++ includes/common.inc @@ -195,32 +195,6 @@ function drupal_get_region_content($region = NULL, $delimiter = ' ') { } /** - * Get the name of the currently active install profile. - * - * When this function is called during Drupal's initial installation process, - * the name of the profile that's about to be installed is stored in the global - * installation state. At all other times, the standard Drupal systems variable - * table contains the name of the current profile, and we can call variable_get() - * to determine what one is active. - * - * @return $profile - * The name of the install profile. - */ -function drupal_get_profile() { - global $install_state; - - if (isset($install_state['parameters']['profile'])) { - $profile = $install_state['parameters']['profile']; - } - else { - $profile = variable_get('install_profile', 'standard'); - } - - return $profile; -} - - -/** * Set the breadcrumb trail for the current page. * * @param $breadcrumb @@ -4755,6 +4729,7 @@ function drupal_cron_cleanup() { } } + /** * Returns information about system object files (modules, themes, etc.). * @@ -4803,26 +4778,16 @@ function drupal_cron_cleanup() { * - 'name': Name of file without the extension. */ function drupal_system_listing($mask, $directory, $key = 'name', $min_depth = 1) { - $config = conf_path(); - - $profile = drupal_get_profile(); - - $searchdir = array($directory); + $searchdir = array(); $files = array(); - // The 'profiles' directory contains pristine collections of modules and - // themes as organized by a distribution. It is pristine in the same way - // that /modules is pristine for core; users should avoid changing anything - // there in favor of sites/all or sites/ directories. - if (file_exists("profiles/$profile/$directory")) { - $searchdir[] = "profiles/$profile/$directory"; - } - - // Always search sites/all/* as well as the global directories - $searchdir[] = 'sites/all/' . $directory; - - if (file_exists("$config/$directory")) { - $searchdir[] = "$config/$directory"; + // Include directories from the drupal_add_system_directory() function. + foreach (drupal_get_system_directory() as $scope) { + foreach ($scope as $search) { + if (!is_null($search) && file_exists("$search/$directory") && !isset($searchdir[$search])) { + $searchdir[$search] = ($search == '.') ? $directory : "$search/$directory"; + } + } } // Get current list of items diff --git includes/install.core.inc includes/install.core.inc index 3b39e08..6c5a5db 100644 --- includes/install.core.inc +++ includes/install.core.inc @@ -572,6 +572,8 @@ function install_tasks($install_state) { // Now add any tasks defined by the installation profile. if (!empty($install_state['parameters']['profile'])) { + drupal_add_system_directory('profile', 'profiles/' . $install_state['parameters']['profile']); + $function = $install_state['parameters']['profile'] . '_install_tasks'; if (function_exists($function)) { $result = $function($install_state); diff --git modules/simpletest/drupal_web_test_case.php modules/simpletest/drupal_web_test_case.php index 257921a..917cdd7 100644 --- modules/simpletest/drupal_web_test_case.php +++ modules/simpletest/drupal_web_test_case.php @@ -1192,6 +1192,11 @@ class DrupalWebTestCase extends DrupalTestCase { $this->originalProfile = drupal_get_profile(); $clean_url_original = variable_get('clean_url', 0); + // The host profile's collection of modules or themes need to be included + // when running tests that use an alternate install profile but still reside + // in the host profile's directory. + drupal_add_system_directory('after:profile', 'profiles/' . $this->originalProfile); + // Save and clean shutdown callbacks array because it static cached and // will be changed by the test run. If we don't, then it will contain // callbacks from both environments. So testing environment will try