Composer template for Drupal projects
, (*1)
This project template should provide a kickstart for managing your site
dependencies with Composer., (*2)
Usage
-
Install composer.
- Create the project :
composer create-project drupaljedi/project project_name --stability dev --no-interaction
- Execute the
./tools/scripts/before-install.sh project_name
command to prepare project for installation.
- Run docker containers:
cd provision/local && docker-compose up -d && cd -
- Install Drupal:
./tools/scripts/install.sh
With composer require ...
you can download new dependencies to your
installation., (*3)
cd project_name
composer require drupal/be_sure
The composer create-project
command passes ownership of all files to the
project that is created. You should create a new git repository, and commit
all files not excluded by the .gitignore file., (*4)
What does the template do?
When installing the given composer.json
some tasks are taken care of:, (*5)
- Drupal will be installed in the
docroot
-directory.
- Autoloader is implemented to use the generated composer autoloader in
vendor/autoload.php
,
instead of the one provided by Drupal (drupal/vendor/autoload.php
).
- Modules (packages of type
drupal-module
) will be placed in docroot/modules/contrib/
- Theme (packages of type
drupal-theme
) will be placed in docroot/themes/contrib/
- Profiles (packages of type
drupal-profile
) will be placed in docroot/profiles/contrib/
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 (commonly .htaccess),
you may need to merge conflicts if any of your modified files are updated in a
new release of Drupal core., (*6)
Follow the steps below to update your core files., (*7)
- Run
composer update
to update Drupal core, contrib modules and its dependencies.
- Run
git diff
to determine if any of the scaffolding files have changed.
Review the files for any changes and restore any customizations to
.htaccess
or robots.txt
.
- Commit everything all together in a single commit, so
docroot
will remain in
sync with the core
when checking out branches or running git bisect
.
FAQ
Should I commit the contrib modules I download?
Composer recommends NO. They provide argumentation against but also
workrounds if a project decides to do it anyway., (*8)
Should I commit the scaffolding files?
The drupal-scaffold plugin can download the scaffold files (like
index.php, update.php, …) to the docroot/ directory of your project. If you have not customized those files you could choose
to not check them into your version control system (e.g. git). If that is the case for your project it might be
convenient to automatically run the drupal-scaffold plugin after every install or update of your project. You can
achieve that by registering @drupal-scaffold
as post-install and post-update command in your composer.json:, (*9)
"scripts": {
"drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
"post-install-cmd": [
"@drupal-scaffold",
"..."
],
"post-update-cmd": [
"@drupal-scaffold",
"..."
]
},
How can I apply patches to downloaded modules?
If you need to apply patches (depending on the project being modified, a pull
request is often a better solution), you can do so with the
composer-patches plugin., (*10)
To add a patch to drupal module foobar insert the patches section in the extra
section of composer.json:, (*11)
"extra": {
"patches": {
"drupal/foobar": {
"Patch description": "URL to patch"
}
}
}