markdown 如何使用Composer在Drupal 8中应用补丁

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 如何使用Composer在Drupal 8中应用补丁相关的知识,希望对你有一定的参考价值。

# How to apply patches in Drupal 8 with Composer
1. Drupal Installation.   
In this example I will assume that did you install Drupal using *Drupal Composer* project, using an instruction similar to the following:
`$ composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interact`
2. Make sure you have the cweagans/composer-patches composer plugin installed:   
`composer require cweagans/composer-patches`
3. Installing module to patch.      
I will use the module Address to demonstrate how to patch a module.
Using the following module we could install the Address module in our Drupal 8 project.
`$ composer require "drupal/address ~8.1"`
4. Patching the module.   
The Address module works pretty well, but there is an issue related to full configuration import in a site, this issue was reported and fixed in https://www.drupal.org/node/2663412. But at the moment of this article that solution wasn't included in the stable release of Address module.
Including composer lingua, we could say module and themes are packages and their difference remains in package type. To patch a package is need to edit put composer.json file to provide the patch instructions as you can see in the following snippet of code. (Note: the installer paths are just there to show a sibling in the "extras" section, not as something you're supposed to add!)
```
"extra": {
  "installer-paths": {
    "web/core": ["type:drupal-core"],
    "web/libraries/{$name}": ["type:drupal-library"],
    "web/modules/contrib/{$name}": ["type:drupal-module"],
    "web/profiles/contrib/{$name}": ["type:drupal-profile"],
    "web/themes/contrib/{$name}": ["type:drupal-theme"],
    "drush/contrib/{$name}": ["type:drupal-drush"]
  },
  "patches": {
    "drupal/address": {
      "Drupal Addess fix default syncing": "https://www.drupal.org/files/issues/address_syncing.patch"     
    }
  }
}
```
As you could see, the format is a straightforward entry in patches group, providing the package to patch and the URL of the patch to be download with a human comment.
4. Applying your patches.
The next time do you run `composer install` or `composer update` your patches will be applied, and you will get an output similar to the next image.

以上是关于markdown 如何使用Composer在Drupal 8中应用补丁的主要内容,如果未能解决你的问题,请参考以下文章

markdown 使用Composer全局安装PHP工具

markdown 使用不一致的PHP版本更新composer

markdown 在Mac上全球下载Composer

markdown 在Domainfactory上的托管主机上安装Composer

markdown Shell用于使用Docker运行NPM,Composer和PHP之类的东西。

markdown 通过Brew在OSX上设置PHP和Composer