Drupal 8 is all about getting off the island and leveraging things invented elsewhere. With that, we must use a package manager tool. PHP's de facto package manager is now Composer. However, adopting Composer has been a rough spot with the Drupal community.
In this presentation, Matt Glaman will explore Composer and how using it will streamline your workflow.
2. Matt Glaman
Senior Drupal Consultant @ Commerce Guys
Co-maintainer of Drupal Commerce
Author of Drupal 8 Development Cookbook
http://bit.ly/d8-dev-cookbook
15. Install from packaged archive
Drupal.org has a packaging system which
provides zip and tar archives.
These archives come with all third party
dependencies downloaded.
16. Install via Composer template
composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interaction
Creates your project in some-dir
Contains vendor and web directory
Follows current standard application structure
https://github.com/drupal-composer/drupal-project
19. With Composer
composer require drupal/panels
"require": {
"drupal/panels": "3.0-beta4",
}
Use Composer require command to add the dependency
Your composer.json should have the following
BUT WAIT. There’s currently a catch….
20. Drupal.org Composer Façade
https://packages.drupal.org/8
Repository endpoints provide packages
Drupal.org provides a repository endpoint (beta)
Allows Drupal.org projects to be installed via composer
Allows Drupal.org projects to specify 3rd party libraries
Initial community initative: https://github.com/drupal-composer
21. Adding the endpoint to composer.json
composer config repositories.drupal composer https://packages.drupal.org/8
Your composer.json will now have
"repositories": {
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
}
},
22. Version
constraints
~8.2.1: >=8.2.1 <8.3.0
~8.2: >=8.2 <9.0.0
^8.2.1: >=8.2.1 <9.0.0
8.2.0: specifically 8.2.0
Same as everyone else.
semver ftw.
https://blog.madewithlove.be/post/tilde-and-caret-constraints/
https://semver.mwl.be/#?package=drupal%2Fdrupal
Core: 8.2.0, 8.2.1, 8.2.2, 8.3.0-rc1, etc.
Contrib: 8.x-2.0 == 8.2.0, 8.x-2.10 == 8.2.10
25. With Composer
composer update drupal/panels --with-dependencies
Use Composer update command
--with-dependencies
allows all of the package’s dependencies to be updated
Alternatively, could just run composer update for all the things
27. Without Composer (manually)
1. Download latest 8.x.x archive
2. Remove your core and vendor directories
3. Make note of changes to .htaccess, composer.json, or robots.txt.
4. Apply archive contents to site
5. Re-apply changes to .htaccess, composer.json, or robots.txt.
6. Run update.php
https://www.drupal.org/docs/8/update/update-procedure-in-drupal-8
28. With Composer
Modify the shipped composer.json and move drupal/core to a requirement.
"require": {
"composer/installers": "^1.0.21",
"wikimedia/composer-merge-plugin": "~1.3",
"drupal/core": "~8.2"
},
"replace": { },
run composer update drupal/core --with-dependencies and have an up to date Drupal.
31. Using patch files with Composer
Require cweagans/composer-patches as a dependency
It is a Composer plugin
Specify patches in the extra definition
Applies patches on update and install
"extra": {
"patches": {
"drupal/commerce”: {
"#2805625 Drupal.org": "https://www.drupal.org/files/issues/add_a_new_service_to-2805625-4.patch",
"#2805625: GitHub": "https://github.com/drupalcommerce/commerce/pull/511.patch"
}
}
}
32. Resources
Managing Your Drupal Project with Composer
https://glamanate.com/blog/managing-your-drupal-project-composer
Drupal Composer project template
https://github.com/drupal-composer/drupal-project
Drupal Commerce project template
https://github.com/drupalcommerce/project-base
Platform.sh Drupal 8 + Composer template example
https://github.com/platformsh/platformsh-example-drupal/tree/8.x
Amazee Labs Composer recipes (examples of what we covered.)
https://www.amazeelabs.com/en/blog/drupalcomposerrecipes
Notas do Editor
Dependency management is not a new concept.
NodeJS: npm
Frontend JS/CSS: Bower
Ruby: Bundler/Gems
Python: pip
Java: Maven
C#/.NET: nuget
Go: there’s like 10. https://github.com/golang/go/wiki/PackageManagementTools
ObjectiveC: cocoapods
Inspired by npm and bundler
Provides a way to easily share and use libraries
Not like PEAR - which installed to global includes directory and didn’t use PSR standards for autoloading.
Package information
Dependencies
Developer dependencies
Additional metadata
See Gemfile.lock
Contains installable package information
Provides a repeatable install across instances
downloads and installs dependencies,
builds the class autoloader.
If a .lock file is available it will install based off of the metadata. Otherwise it will calculated and resolve the download information for dependencies.
“Drush en -y panels_ipe” thx Drush for downloading and enabling everything.
Everything isn’t worked out yet for working with Drupal and Composer
Wanted “hunt and peck” but this was more suitable.
Wanted “hunt and peck” but this was more suitable.