1

I have installed the module Drush Help to see the module's Drush commands in the module help page. But when I go to see the help page of a module that use in the drush commands drush constants like DRUSH_BOOTSTRAP_DRUPAL_FULL I got a Notice because this constant is only defined in drush, and not for Drupal.

You can see this problem if you install the Drush Help and the Node Revision Delete modules (the Drupal 7 version): Visit admin/help/node_revision_delete and you will see this notice message.

Notice: Use of undefined constant DRUSH_BOOTSTRAP_DRUPAL_FULL - assumed 'DRUSH_BOOTSTRAP_DRUPAL_FULL' in node_revision_delete_drush_command()

So the problem is that Drupal can't reach the file includes/bootstrap.inc where the constant is defined. I can include the file but the problem is that I need to know where Drush is installed.

How to find where Drush is installed to include a file in my module?

  • In bash: ll `which drush` will give you the path to the binary, which is very likely the path to the root of the installation – Clive Nov 22 '17 at 17:06
  • @Clive but always ll will not be available in all the systems. – Adrian Cid Almaguer Nov 22 '17 at 17:10
  • Yeah you’ll need to adjust for your own environment obviously. However you list files, use that – Clive Nov 22 '17 at 17:13
  • @Clive well I found a temporary solution. See the answer. – Adrian Cid Almaguer Nov 22 '17 at 17:15
1

A temporary solution that I found is define the same constants in the drush_help.module file.

/**
 * Constants defined by drush in the includes/bootstrap.inc file.
 *
 * To see why we need to do this please read:
 * https://drupal.stackexchange.com/q/250786/28275
 */
define('DRUSH_BOOTSTRAP_NONE', -1);
define('DRUSH_BOOTSTRAP_MAX', -2);
define('DRUSH_BOOTSTRAP_DRUSH', 0);
define('DRUSH_BOOTSTRAP_DRUPAL_ROOT', 1);
define('DRUSH_BOOTSTRAP_DRUPAL_SITE', 2);
define('DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION', 3);
define('DRUSH_BOOTSTRAP_DRUPAL_DATABASE', 4);
define('DRUSH_BOOTSTRAP_DRUPAL_FULL', 5);
define('DRUSH_BOOTSTRAP_DRUPAL_LOGIN', 6);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.