function pm_drush_pm_download_destination_alter

8.0.x pm_drush_pm_download_destination_alter(&$request, $release)
6.x pm_drush_pm_download_destination_alter(&$project, $release)
7.x pm_drush_pm_download_destination_alter(&$request, $release)
4.x pm_drush_pm_download_destination_alter(&$project, $release)
5.x pm_drush_pm_download_destination_alter(&$project, $release)
master pm_drush_pm_download_destination_alter(&$request, $release)

Implementation of hook_drush_pm_download_destination_alter().

Built-in download-destination-alter hook. This particular version of the hook will move modules that contain only Drush commands to /usr/share/drush/commands if it exists, or $HOME/.drush if the site-wide location does not exist.


commands/pm/, line 271
pm-download command implementation.


function pm_drush_pm_download_destination_alter(&$request, $release) {
  // A module is a pure Drush command if it has no .info.yml (8+) and contains no
  // files.  Skip this test for Drush itself, though; we do
  // not want to download Drush to the ~/.drush folder.
  if (in_array($request['project_type'], array('module', 'utility')) && ($request['name'] != 'drush')) {
    $drush_command_files = drush_scan_directory($request['full_project_path'], '/.*\');
    if (!empty($drush_command_files)) {
      $pattern = drush_drupal_major_version() >= 8 ? '/.*\.info/' : '/.*\.module/';
      $module_files = drush_scan_directory($request['full_project_path'], $pattern);
      if (empty($module_files)) {
        $install_dir = drush_get_context('DRUSH_SITE_WIDE_COMMANDFILES');
        if (!is_dir($install_dir) || !is_writable($install_dir)) {
          $install_dir = drush_get_context('DRUSH_PER_USER_CONFIGURATION');
        // Make the .drush dir if it does not already exist.
        if (!is_dir($install_dir)) {
          drush_mkdir($install_dir, FALSE);
        // Change the location if the mkdir worked.
        if (is_dir($install_dir)) {
          $request['project_install_location'] = $install_dir;
      // We need to clear the Drush commandfile cache so that
      // our newly-downloaded Drush extension commandfiles can be found.