function DrupalBoot::commandfile_searchpaths

8.0.x DrupalBoot.php DrupalBoot::commandfile_searchpaths($phase, $phase_max = FALSE)
7.x DrupalBoot.php DrupalBoot::commandfile_searchpaths($phase, $phase_max = FALSE)
master DrupalBoot.php DrupalBoot::commandfile_searchpaths($phase, $phase_max = FALSE)

File

lib/Drush/Boot/DrupalBoot.php, line 106

Namespace

Drush\Boot

Class

DrupalBoot

Code

function commandfile_searchpaths($phase, $phase_max = FALSE) {
  if (!$phase_max) {
    $phase_max = $phase;
  }

  $searchpath = array();
  switch ($phase) {
    case DRUSH_BOOTSTRAP_DRUPAL_ROOT:
      $drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT');
      $searchpath[] = $drupal_root . '/../drush';
      $searchpath[] = $drupal_root . '/drush';
      $searchpath[] = $drupal_root . '/sites/all/drush';

      // Add the drupalboot.drush.inc commandfile.
      // $searchpath[] = __DIR__;
      break;
    case DRUSH_BOOTSTRAP_DRUPAL_SITE:
      // If we are going to stop bootstrapping at the site, then
      // we will quickly add all commandfiles that we can find for
      // any extension associated with the site, whether it is enabled
      // or not.  If we are, however, going to continue on to bootstrap
      // all the way to DRUSH_BOOTSTRAP_DRUPAL_FULL, then we will
      // instead wait for that phase, which will more carefully add
      // only those Drush commandfiles that are associated with
      // enabled modules.
      if ($phase_max < DRUSH_BOOTSTRAP_DRUPAL_FULL) {
        $searchpath = array_merge($searchpath, $this->contrib_modules_paths());

        // Adding commandfiles located within /profiles. Try to limit to one profile for speed. Note
        // that Drupal allows enabling modules from a non-active profile so this logic is kinda dodgy.
        $cid = drush_cid_install_profile();
        if ($cached = drush_cache_get($cid)) {
          $profile = $cached->data;
          $searchpath[] = "profiles/$profile/modules";
          $searchpath[] = "profiles/$profile/themes";
        }
        else {
          // If install_profile is not available, scan all profiles.
          $searchpath[] = "profiles";
          $searchpath[] = "sites/all/profiles";
        }

        $searchpath = array_merge($searchpath, $this->contrib_themes_paths());
      }
      break;
    case DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION:
      // Nothing to do here anymore. Left for documentation.
      break;
    case DRUSH_BOOTSTRAP_DRUPAL_FULL:
      // Add enabled module paths, excluding the install profile. Since we are bootstrapped,
      // we can use the Drupal API.
      $ignored_modules = drush_get_option_list('ignored-modules', array());
      $cid = drush_cid_install_profile();
      if ($cached = drush_cache_get($cid)) {
        $ignored_modules[] = $cached->data;
      }
      foreach (array_diff(drush_module_list(), $ignored_modules) as $module) {
        $filepath = drupal_get_path('module', $module);
        if ($filepath && $filepath != '/') {
          $searchpath[] = $filepath;
        }
      }

      $searchpath[] = drupal_get_path('theme', drush_theme_get_admin());
      $searchpath[] = drupal_get_path('theme', drush_theme_get_default());
      break;
  }

  return $searchpath;
}