Composer template for Drupal projects
This project template should provide a kickstart for managing your site
dependencies with Composer. Based on the excellent Drupal Composer Project
it introduces some modifications:, (*1)
- Dev dependencies like Behat or PHPUnit are removed, you can add them yourself as needed.
- Public and private files are placed outside the web root.
- The config sync folder is placed outside the web root.
- During installation, a local settings file is used to point to modified files and config location.
- Creates "contrib" and "custom" folders for modules, themes, libraries, profiles and drush plugins by default.
- Adds the Composer Parallel Install plugin to speed up downloads.
- Adds the Composer Merge plugin to manage dependencies of custom modules.
- Adds the Asset Packagist repository to manage npm / bower dependencies.
Usage
First you need to install composer., (*2)
After that you can create the project:, (*3)
composer create-project -s dev drubb/drupal-simple some-dir
Replace 'some-dir' by your project root folder, or '.' for current directory., (*4)
If you get an outdated version of Drupal core, please check your php extensions. Latest versions of core
might require additional extensions. Here's an example how to check this:, (*5)
composer why-not drupal/core:8.6.1
What does the template do?
When installing the given composer.json
some tasks are taken care of:, (*6)
- The current stable Drupal 8 Version will be installed in the
web
-directory.
- Autoloader is implemented to use the generated composer autoloader in
vendor/autoload.php
,
instead of the one provided by Drupal (web/vendor/autoload.php
).
- Modules (packages of type
drupal-module
) will be placed in web/modules/contrib/
- Themes (packages of type
drupal-theme
) will be placed in web/themes/contrib/
- Profiles (packages of type
drupal-profile
) will be placed in web/profiles/contrib/
- Libraries (packages of type
drupal-library
) will be placed in web/libraries/contrib/
- Drush plugins (packages of type
drupal-drush
) will be placed in drush/contrib
- Creates default writable versions of
settings.php
, settings.local.php
and services.yml
.
- Creates
sites/default/files
-directory, using a symlink to files/public
- Latest version of Drush is installed locally for use at
vendor/bin/drush
.
- Latest version of Drupal Console is installed locally for use at
vendor/bin/drupal
.
Updating Drupal Core
This project will attempt to keep all of your Drupal Core files up-to-date; the
project drupal-composer/drupal-scaffold
is used to ensure that your scaffold files are updated every time drupal/core is
updated. If you customize any of the "scaffolding" files (eg .htaccess or robots.txt),
you may need to merge conflicts if any of your modified files are updated in a
new release of Drupal core., (*7)
Follow the steps below to update your core files (run this commands in your project root):, (*8)
- Run
composer update drupal/core --with-dependencies
to update Drupal Core and its dependencies.
- Run
git diff
to determine if any of the scaffolding files has changed.
Review the files for any changes and restore any customizations to e.g.
.htaccess
or robots.txt
. Commit your changes to git.
Installing contributed modules
You can add contributed modules using the composer require command. Example:, (*9)
composer require drupal/devel
, (*10)
Run this command in your project root., (*11)
Updating contributed modules
You can update contributed modules using the composer update command. Example:, (*12)
composer update drupal/devel --with-dependencies
, (*13)
Run this command in your project root., (*14)
Using Composer with custom modules
You can add Composer support to your custom modules using the following steps (run these commands in your module folder):, (*15)
- Add a basic composer.json file to your module's folder:
composer init --n
- Add dependencies for your custom module:
composer require mpdf/mpdf --no-update
In this example, the custom module is using the mpdf PHP library. The flag '--no-update' tells
Composer not to download the library to your custom module's folder, as we need to store it in the
central vendor folder of our project. The Composer Merge plugin takes care of this, we'll just need
to update our main Composer manifest (composer.json):, (*16)
composer update --lock
Run this command in your project root. This will add our custom module's dependency to the main Composer manifest., (*17)
How can I apply patches to downloaded modules?
If you need to apply patches, you can do so with the
composer-patches plugin., (*18)
To add a patch to Drupal module foobar insert the patches section in the extra
section of composer.json, in your project root:, (*19)
"extra": {
"patches": {
"drupal/foobar": {
"Patch description": "URL to patch"
}
}
}