- Notifications
You must be signed in to change notification settings - Fork929
🚀 Composer template for Drupal projects. Quick installation via "composer create-project drupal-composer/drupal-project"
License
drupal-composer/drupal-project
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This project template provides a starter kit for managing your sitedependencies withComposer.
Important
Drupal 11 branch is available!
- Drupal will be installed in the
web
directory. - Generated composer autoloader
vendor/autoload.php
is used instead ofweb/vendor/autoload.php
provided by Drupal core. - Modules (packages of type
drupal-module
) will be placed inweb/modules/contrib
directory. - Themes (packages of type
drupal-theme
) will be placed inweb/themes/contrib
directory. - Profiles (packages of type
drupal-profile
) will be placed inweb/profiles/contrib
directory. - Creates default writable versions of
settings.php
andservices.yml
. - Creates
web/sites/default/files
directory. - Drush is installed for use as
vendor/bin/drush
. - Provides anexample of the
.env
file.
Note
The instructions below refer to theglobal Composer installation.You might need to replacecomposer
withphp composer.phar
(or similar)for your setup.
Create your project:
composer create-project drupal-composer/drupal-project:10.x-dev some-dir --no-interaction
Thecomposer create-project
command passes ownership of all files to theproject that is created. You should create a new Git repository, and commitall files not excluded by the.gitignore
file.
Usecomposer require
to include and download dependencies for your project.
cd some-dircomposer require drupal/devel
By default, this project is set to install only stable releases of dependencies,as specified by"minimum-stability": "stable"
incomposer.json
. If you needto use non-stable releases (e.g.,alpha
,beta
,RC
), you can modify theversion constraint to allow for such versions. For instance, to require a betaversion of a module:
composer require drupal/devel:1.0.0-beta1
Alternatively, you can globally adjust the stability settings by modifyingcomposer.json
to include the desired stability level and explicitly allow it:
{"minimum-stability":"beta","prefer-stable":true}
This configuration ensures that stable releases are preferred, but allows theinstallation of non-stable packages when necessary.
You can manage front-end asset libraries with Composer thanks to theasset-packagist repository. Composer will detectand install new versions of a library that meet the stated constraints.
composer require bower-asset/dropzone
The installation path of a specific library can be controlled by adding it totheextra.installer-paths
configuration precedingweb/libraries/{$name}
.For example, thechosen
Drupal module expects thechosen
library to belocated onweb/libraries/chosen
, butcomposer require npm-asset/chosen-js
installs the library intoweb/libraries/chosen-js
. The following configurationoverrides installation it into the expected directory:
{"extra": {"installer-paths": {"web/libraries/chosen": ["npm-asset/chosen-js" ],"web/libraries/{$name}": ["type:drupal-library","type:npm-asset","type:bower-asset" ] } }}
For more details, seehttps://asset-packagist.org/site/about
This project will attempt to keep all of your Drupal Core files up-to-date; theprojectdrupal/core-composer-scaffoldis used to ensure that your scaffold files are updated every timedrupal/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 anew release of Drupal core.
Follow the steps below to update your Drupal core files.
- 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 have changed.Review the files for any changes and restore any customizations to.htaccess
orrobots.txt
. - Commit everything all together in a single commit, so
web
will remain insync with thecore
when checking out branches or runninggit bisect
. - In the event that there are non-trivial conflicts in step 2, you may wishto perform these steps on a branch, and use
git merge
to combine theupdated core files with your customized files. This facilitates the useof athree-way merge tool such as kdiff3. This setup is not necessary if your changes are simple;keeping all of your modifications at the beginning or end of the file is agood strategy to keep merges easy.
Composer recommendsno. They provideargumentation against but alsoworkarounds if a project decides to do it anyway.
TheDrupal Composer Scaffoldplugin can download the scaffold files (likeindex.php
,update.php
etc.) totheweb
directory of your project. If you have not customized those files youcould 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 automaticallyrun the drupal-scaffold plugin after every install or update of your project.You can achieve that by registering@composer drupal:scaffold
aspost-install
andpost-update
command in yourcomposer.json
:
"scripts": {"post-install-cmd": ["@composer drupal:scaffold","..." ],"post-update-cmd": ["@composer drupal:scaffold","..." ]},
If you need to apply patches, you can do so with thecomposer-patches plugin includedin this project.
To add a patch to Drupal modulefoobar
, insert thepatches
section in theextra
section ofcomposer.json
:
"extra": {"patches": {"drupal/foobar": {"Patch description":"URL or local path to patch" } }}
There are 2 places where Composer will be looking for PHP version requirementswhen resolving dependencies:
- The
require.php
version value incomposer.json
. - The
config.platform
version value incomposer.json
.
The purpose ofrequire.php
is to set the minimum PHP language requirementsfor a package. For example, the minimum version required for Drupal 10.0 is8.0.2
or above, which can be specified as>=8
.
The purpose ofconfig.platform
is to set the PHP language requirements for thespecific instance of the package running in the current environment. Forexample, while the minimum version required for Drupal 10 is8.0.2
or above,the actual PHP version on the hosting provider could be8.1.0
. The value ofthis field should provide your exact version of PHP with all 3 parts of theversion.
This project includesdrupal/core
which already hasrequire.php
added. Yourwould inherit that constraint. There is no need to addrequire.php
to yourcomposer.json
.
config.platform
is a platform-specific. It is recommended to specifyconfig.platform
as aspecific version (e.g.8.1.19
) constraint to ensurethat only the package versions supported by your current environment are used.
"config": {"platform": {"php":"8.1.19" }},
About
🚀 Composer template for Drupal projects. Quick installation via "composer create-project drupal-composer/drupal-project"
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.