|
1 | 1 | # Patches
|
2 |
| - |
3 |
| -All modifications to contributed projects must be performed via a patch and must be applied via composer.json. |
4 | 2 |
|
5 |
| -Drupal core and contrib can be patched in `composer.json` using [cweagans/composer-patches](https://github.com/cweagans/composer-patches), which is required by default. Patch information should be specified in the JSON array in accordance with the following schema: |
| 3 | +All modifications to contributed projects and most modifications to Drupal core must be performed via patches. |
| 4 | + |
| 5 | +## Applying patches |
| 6 | + |
| 7 | +Patches can be applied by referencing them in `composer.json` in the format below. BLT then uses [cweagans/composer-patches](https://github.com/cweagans/composer-patches) to apply the patches on any subsequent site builds. |
| 8 | + |
| 9 | +Patch information should be specified in the JSON array in accordance with the following schema: |
6 | 10 |
|
7 | 11 | "extra": {
|
8 | 12 | "patches": {
|
9 | 13 | "drupal/core": {
|
10 |
| - "Ignore front end vendor folders to improve directory search performance": "https://www.drupal.org/files/issues/ignore_front_end_vendor-2329453-116.patch" |
| 14 | + "Ignore front end vendor folders to improve directory search performance": "https://www.drupal.org/files/issues/ignore_front_end_vendor-2329453-116.patch", |
| 15 | + "My custom local patch": "./patches/drupal/some_patch-1234-1.patch" |
11 | 16 | }
|
12 | 17 | }
|
13 | 18 | },
|
14 | 19 |
|
| 20 | +Remember to run `composer update` after modifying `composer.json` to actually apply the patch and update `composer.lock`, and commit the modified lock file. |
| 21 | + |
| 22 | +## Storing patches |
| 23 | + |
15 | 24 | Patches that can be contributed on Drupal.org should be contributed there. Please follow [Drupal.org's patch naming conventions](https://www.drupal.org/node/1054616#naming-conventions) when creating patches.
|
16 | 25 |
|
17 |
| -Patches that cannot be contributed publicly are extremely rare. In the unlikely event that such a change must be committed, all project-specific patches should reside in this directory. This ensures one consistent place for patches and avoids accidental patch deletion. See [instructions for using a local patch](https://github.com/cweagans/composer-patches#using-an-external-patch-file). |
| 26 | +Patches that cannot be contributed publicly are extremely rare. In the unlikely event that such a change must be committed, all project-specific patches should reside in this directory. This ensures one consistent place for patches and avoids accidental patch deletion. |
18 | 27 |
|
19 | 28 | Patches should be stored in sub-directories based on project name being patched.
|
20 | 29 |
|
21 | 30 | Examples:
|
22 | 31 |
|
23 | 32 | - /patches/drupal/some_patch-1234-1.patch
|
24 | 33 | - /patches/ctools/another_patch_name-9876-12.patch
|
| 34 | + |
| 35 | +## Gotchas |
| 36 | + |
| 37 | +Note that Composer can only patch files that are distributed with Composer packages. This means that certain files (such as the Drupal core `.htaccess` and `robots.txt`) cannot be patched via Composer, since they are not included in the Drupal core Composer package (in fact Drupal Scaffold individually creates these files on updates). |
| 38 | + |
| 39 | +In order to modify `.htaccess` and other unpatchable root files, simply modify the file in place, commit it to Git, and make the following change in `composer.json`: |
| 40 | + |
| 41 | + "extra": { |
| 42 | + "drupal-scaffold": { |
| 43 | + "excludes": [ |
| 44 | + ".htaccess" |
| 45 | + ] |
| 46 | + } |
| 47 | + }, |
| 48 | + |
| 49 | +Also note that there’s currently a quirk in the Drupal packaging system that makes it difficult to patch module and theme `.info.yml` files. If you have trouble applying a patch that modifies an info file, see this issue for a description and workaround: https://www.drupal.org/node/2858245 |
0 commit comments