|
| 1 | +# Composer template for Drupal projects |
| 2 | + |
| 3 | +[](https://travis-ci.org/drupal-composer/drupal-project) |
| 4 | + |
| 5 | +This project template provides a starter kit for managing your site |
| 6 | +dependencies with [Composer](https://getcomposer.org/). |
| 7 | + |
| 8 | +If you want to know how to use it as replacement for |
| 9 | +[Drush Make](https://github.com/drush-ops/drush/blob/8.x/docs/make.md) visit |
| 10 | +the [Documentation on drupal.org](https://www.drupal.org/node/2471553). |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +First you need to [install composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx). |
| 15 | + |
| 16 | +> Note: The instructions below refer to the [global composer installation](https://getcomposer.org/doc/00-intro.md#globally). |
| 17 | +You might need to replace `composer` with `php composer.phar` (or similar) |
| 18 | +for your setup. |
| 19 | + |
| 20 | +After that you can create the project: |
| 21 | + |
| 22 | +``` |
| 23 | +composer create-project drupal-composer/drupal-project:7.x-dev some-dir --no-interaction |
| 24 | +``` |
| 25 | + |
| 26 | +With `composer require ...` you can download new dependencies to your |
| 27 | +installation. |
| 28 | + |
| 29 | +``` |
| 30 | +cd some-dir |
| 31 | +composer require drupal/devel:~1.0 |
| 32 | +``` |
| 33 | + |
| 34 | +The `composer create-project` command passes ownership of all files to the |
| 35 | +project that is created. You should create a new git repository, and commit |
| 36 | +all files not excluded by the .gitignore file. |
| 37 | + |
| 38 | +## What does the template do? |
| 39 | + |
| 40 | +When installing the given `composer.json` some tasks are taken care of: |
| 41 | + |
| 42 | +* Drupal will be installed in the `web`-directory. |
| 43 | +* Modules (packages of type `drupal-module`) will be placed in `web/sites/all/modules/contrib/` |
| 44 | +* Theme (packages of type `drupal-module`) will be placed in `web/sites/all/themes/contrib/` |
| 45 | +* Profiles (packages of type `drupal-profile`) will be placed in `web/profiles/` |
| 46 | +* Libraries (packages of type `drupal-library`) will be placed in `web/sites/all/libraries/` (See Libraries) |
| 47 | +* Helps for using other PHP packages almost similar to the Drupal 8 version |
| 48 | +* Creates default writable versions of `settings.php`. |
| 49 | +* Creates `web/sites/default/files`-directory. |
| 50 | +* Latest version of drush is installed locally for use at `vendor/bin/drush`. |
| 51 | + |
| 52 | +## Generate composer.json from existing project |
| 53 | + |
| 54 | +With using [the "Composer Generate" drush extension](https://www.drupal.org/project/composer_generate) |
| 55 | +you can now generate a basic `composer.json` file from an existing project. Note |
| 56 | +that the generated `composer.json` might differ from this project's file. |
| 57 | + |
| 58 | +## How to enable the Composer autoloader in your Drupal 7 website |
| 59 | + |
| 60 | +The skeleton already installs the `composer_autoloader` module. Just enable it in the website before enabling |
| 61 | +any possible module that have dependencies various packages. |
| 62 | + |
| 63 | +## Libraries |
| 64 | + |
| 65 | +Libraries normally would be extra packages that need to be public available (CSS and JS). |
| 66 | +Normally this are not maintained using Composer, but if you want to have a 100% Composer deployment and benefit from patches you can use in `composer.json` this example, changing the `repositories` section and adding in `require` section: |
| 67 | +``` |
| 68 | +
|
| 69 | +"repositories": [ |
| 70 | + ... |
| 71 | + { |
| 72 | + "type": "package", |
| 73 | + "package": { |
| 74 | + "name": "kenwheeler/slick", |
| 75 | + "version": "1.6.0", |
| 76 | + "dist": { |
| 77 | + "url": "https://github.com/kenwheeler/slick/archive/1.6.0.zip", |
| 78 | + "type": "zip" |
| 79 | + }, |
| 80 | + "source": { |
| 81 | + "url": "https://github.com/kenwheeler/slick.git", |
| 82 | + "type": "git", |
| 83 | + "reference": "1.6.0" |
| 84 | + }, |
| 85 | + "type": "drupal-library" |
| 86 | + } |
| 87 | + } |
| 88 | +], |
| 89 | +"require": { |
| 90 | + ... |
| 91 | + "kenwheeler/slick": "~1.6.0" |
| 92 | +}, |
| 93 | +``` |
| 94 | +After this run `composer update --lock` to install just the manually managed package. |
| 95 | +_(You may run `composer require "kenwheeler/slick:~1.6.0"` as well if you add just the package definition)_ |
| 96 | + |
| 97 | +## FAQ |
| 98 | + |
| 99 | +### Should I commit the contrib modules I download? |
| 100 | + |
| 101 | +Composer recommends **no**. They provide [argumentation against but also |
| 102 | +workrounds if a project decides to do it anyway](https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md). |
| 103 | + |
| 104 | +### How can I apply patches to downloaded modules? |
| 105 | + |
| 106 | +If you need to apply patches (depending on the project being modified, a pull |
| 107 | +request is often a better solution), you can do so with the |
| 108 | +[composer-patches](https://github.com/cweagans/composer-patches) plugin. |
| 109 | + |
| 110 | +To add a patch to drupal module foobar insert the patches section in the extra |
| 111 | +section of composer.json: |
| 112 | +```json |
| 113 | +"extra": { |
| 114 | + "patches": { |
| 115 | + "drupal/foobar": { |
| 116 | + "Patch description": "URL or local path to patch" |
| 117 | + } |
| 118 | + } |
| 119 | +} |
| 120 | +``` |
| 121 | +### How do I switch from packagist.drupal-composer.org to packages.drupal.org? |
| 122 | + |
| 123 | +Follow the instructions in the [documentation on drupal.org](https://www.drupal.org/docs/develop/using-composer/using-packagesdrupalorg). |
| 124 | + |
| 125 | +### How do I specify a PHP version ? |
| 126 | + |
| 127 | +This project supports PHP 5.3 as minimum version (see [Drupal 7 PHP requirements](https://www.drupal.org/docs/7/system-requirements/php-requirements)), however it's possible that a `composer update` will upgrade some package that will then require PHP 7+. |
| 128 | + |
| 129 | +To prevent this you can add this code to specify the PHP version you want to use in the `config` section of `composer.json`: |
| 130 | +```json |
| 131 | +"config": { |
| 132 | + "sort-packages": true, |
| 133 | + "platform": { |
| 134 | + "php": "5.3.3" |
| 135 | + } |
| 136 | +}, |
| 137 | +``` |
0 commit comments