1) Drush can now use Composer to manage dependencies and extensions for both Drupal 8 and Drupal 7 sites. Composer is used to manage Drush and Drupal core together.
2) Drush implements a "site-local" approach to avoid dependency hell issues between extensions and core. Each Drupal site can have its own isolated version of Drush that will be used.
3) Drush extensions that use Composer libraries need to be included in the Drupal project's composer.json file. The drush_autoload function ensures extensions work with both Composer-managed and non-Composer sites.
3. It is now possible to use Composer to
add code directly to Drupal:
drush dl drupal-8
cd drupal-8
composer require drupal/og:8.*
composer update will not update
drupal/core; use drush pm-update
drupal for this.
3
Standard Composer used in D8
10. The Multiple Autoloaders Problem
10
Two autoloaders may directly or indirectly include the same dependent library.
Drupal 8
require autoload.php
Badly-Behaved Drush Extension
require autoload.php
"name": "symfony/event-dispatcher",
"version": "v2.7.5",
"name": "symfony/event-dispatcher",
"version": "3.*",
14. Drush dispatch now happens in four phases:
14
Drush Dispatch
Drush Finder Drush Wrapper Drush Launcher
Drush
Application
15. 15
Drush Finder
Responsible for finding the correct Drush to run
● Checks to see if it can find a Drupal site
● If the Drupal site contains a Drush script, use it
● If no Site-Local Drush is found, use global Drush
Does not look at alias files.
PHP Script
16. Optional. Located at the Drupal Root if it exists.
User may customize this script to:
● Add site-specific options (e.g. commandfile
locations)
● Select the location of the Drush launcher (if in a
non-standard location)
If there is no Drush Wrapper, then the Drush Finder
will find and execute the Drush Launcher.
16
Drush Wrapper
Shell Script
17. 17
Drush Launcher
Sets up the PHP operating environment.
● Select php.ini file to use
● Select php executable to use
● Passes info about environment to Drush
Always launches the Drush that is located next to it.
Shell Script
18. 18
Drush Application
Contains all the code that is Drush.
● Load configuration and command file
● Parse site alias files
● Might dispatch again, e.g. if site alias is remote
PHP
Application
19. Manage Drush and Drupal
Place Drush and Drupal in the same composer.json file:
cd /path/to/drupal-8-root
composer require drush/drush:8.*
It is also possible to use site-local Drush with a non-Composer-managed
Drupal site just to attach a specific version of Drush to that site:
cd /path/to/old/drupal-root
composer require drush/drush:6.*
19
CRITICAL
21. PROBLEM:
A Drush extension desires to use Composer
Libraries, but also wants to work with both
Composer-managed sites, and sites that do
not use Composer.
SOLUTION:
Include a composer.json file as usual, and
require libraries there. In your drush extension’
s hook_drush_init, call drush_autoload
(__FILE__).
21
Composer Libraries in Extensions
my.drush.inc:
function my_drush_init() {
drush_autoload(__FILE__);
}
22. IT’S SIMPLE.
If Drush has located a Drupal site that has an autoloader, then it assumes that
all extensions that need an autoloader are part of the Drupal site’s composer.
json file. Drush only loads Drupal’s autoload.php.
If the Drupal site does not have an autoloader, then Drush will find the
extension’s autoloader, and load it.
AN EXTENSION CAN’T GET THIS RIGHT. ALWAYS USE
drush_autoload.
22
drush_autoload Function
23. Global Extensions
23
Drush Extensions that use Composer libraries must be included locally as part
of your Drupal project:
cd /path/to/project
composer require drupal/drush_iq
Policy files can continue to live in a global location, e.g. $HOME/.drush.
27. To keep development modules out of exported configuration, define:
__ROOT__/drush/drushrc.php:
$command_specific['config-export']['skip-modules'] = array('devel');
$command_specific['config-import']['skip-modules'] = array(‘devel');
This only works with the Drush config-import and config-export
commands. Use caution with the Configuration Synchronization admin page.
27
Configuration Filter
29. Drush and Drupal Console
29
The more code you have, the more code you
have to maintain.
However, the maintenance process adds value.
New code should benefit from existing code.
Duplicate functions that do the same thing should
be avoided to reduce maintenance requirements.
&
30. Drush Bootstrap Refactor
30
Drush now has separate bootstrap
classes for each framework
Boot
validRoot($path);
DrupalBoot6
validRoot($path);
DrupalBoot7
validRoot($path);
DrupalBoot8
validRoot($path);
SOMEDAY?
31. By factoring Site Aliases and Backend Invoke into separate libraries, the “Drush
Finder” can handle remote dispatches.
31
Refactor into Composer Libraries
Drush Finder Drush Wrapper Drush Launcher Drush Application