Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console and Services
Drupal + composer = new love !?
-
Upload
nuppla -
Category
Technology
-
view
495 -
download
0
Transcript of Drupal + composer = new love !?
Wolfgang Ziegler // fago
● More than 10 years of Drupal experience● Drupal Core Developer and Maintainer der Entity &
Form Subsysteme● Leading force behind the Drupal 8 Entity Field API
improvements
Wolfgang Ziegler // fago
Creator and Maintainer of modules like● Entity API● Rules● Profile2● Field Collection
Overview● Dependency manager for PHP● Use and publish packages● Package-metadata: composer.json● Repository: packagist.org
PHP Namespaces<?phpnamespace MyProject\Component;
use Symfony\Component\HttpFoundation\Request;
class SomeClass { public function someMethod(Request $request) { if ($request>getPort() != 80) { throw new \LogicException("Application may work on port 80 only."); } }}
composer.json{
"name": "drupal/drupal",
"description": "Drupal is an open source content management....",
"type": "drupalcore",
"require": {
"php": ">5.4.413",
"twig/twig": "1.15.*",
"symfony/classloader": "2.5.*",
"symfony/dependencyinjection": "2.5.*",
"symfony/eventdispatcher": "2.5.*",
"symfony/httpfoundation": "2.5.*",
"symfony/httpkernel": "2.5.*",
"symfony/routing": "2.5.*",
"symfony/validator": "2.5.*",
Providing a package● Add composer.json● Tag versions Semantic versioning→
● Add Git repository to packagist.org
Using it in a project
git clone branch 8.1.x https://git.drupal.org/project/drupal.git
cd drupal
composer install
What happens?● Downloads code and puts it into ./vendor
(or somewhere else)● Generates a class autoloader● Writes lock file → composer.lock
Composer update & locks● composer update
– Update all the dependencies and write new lock file
● composer install – Apply what's recorded in the lock file
Composer & VCS● Commit composer.json● For projects: Commit composer.lock● For libraries: Commit composer.lock for
tests● Avoid commit vendor files
Versions & Composer● Semantic: Major, minor & patch versions● Require versions like 7.3.* to only get bug
fixes● composer supports many different version
constraints● Do not specify a concrete version, use the lock
file
Versions & Composer● Semantic: Major, minor & patch versions● Require versions like 7.3.* to only get bug
fixes● composer supports many different version
constraints● Do not specify a concrete version, use the lock
file
Components in Drupal 8● Symfony components (...)● Twig● PHPUnit● Guzzle● ZendFeed● Doctrine (Annotations)
Composer & Drupal 8.1
● ./vendor is gone!● composer install is your friend!● Nothing changes for tarballs
Prediction● Most Drupal 8 sites will require composer● Drupal commerce is going to depend on
composer● Rules 8.x might do so also● and more will follow
Composer & Drupal Projects● Composer replaces drush make● composer install drush make makefile↔● Support for Drupal modules via:
– https://packagist.drupalcomposer.org/
● Custom repositories● Extendable via scripts
Start a new d8 project
● github.com/drupalcomposer/drupalproject
● composer createproject drupalcomposer/drupalproject:8.xdev somedir stability dev nointeraction
What does it do?● Adds Drupal into the „web“ dir● Adds folder structure, drush, Drupal console,
…● Custom projects can add more stuff and/or
customize things● Requires own packagist/satis
Drupal modules & ./vendor?● Composer package types:
– Library– Project– Drupal-module– Drupal-Theme– Drupal-profile– Drupal-drush
Drupal 7● New project? Check out →github.com/drupalcomposer/drupalproject
● Existing project? composer_generate→drupal.org/project/composer_generate
● Or just use it for adding vendors!
Adding vendors● Composer Manager
– Aggregates composer.json of modules● wikimedia/composer-merge-plugin
– Include composer.json of modules using a wildcard
Gotchas● Prefer „dist“ packages for fast builds● „composer require“ instead of drush dl +
editing make files● Patches? cweagans/composer-patches→
or just fork & add your repo
Update a single modulecomposer update drupal/module
composer update drupal/module withdepdendencies
Deploy from Git?● Commit vendor...● Or just commit vendor on release● Watch out for packages installed from
source● Use composer scripts to update Git
Deployments
● Add project specific drush● Use composer scripts or robo● Requires composer / robo on the server or
added to the repo only
composer scripts "scripts": {
"drush": "drush local include=web/sites/all/drush/drudrush r web",
"deploy": "drush local include=web/sites/all/drush/drudrush r web deploy",
},
composer scripts
● Uses vendor binaries!● React on events like
– Post-package-install– Post-create-project-cmd– ..
● Reference other scripts via @script