跳转到主要内容
你行网

Main navigation

  • 首页
  • Drupal
  • 编程与开发
  • 数据库
  • 操作系统与应用
  • 服务器与运维
  • 社区
User account menu
  • 登录

面包屑

  1. 首页

如何使用composer在drupal 8中应用补丁

由 hrs, 16 五月, 2022

Sometimes, when we use a contrib module in Drupal, we encounter a bug. Chances are that someone has already fixed it and contributed a patch to the Drupal community.

有时,当我们在Drupal中使用contrib模块时,会遇到一个错误。 很有可能有人已经修复它并为Drupal社区贡献了补丁。

First, let’s assume our site root folder is /var/www/public/drupal_site.

首先,假设我们的站点根文件夹为/ var / www / public / drupal_site 。

This example will patch the module Scroll to destination anchors (https://www.drupal.org/project/scroll_to_destination_anchors)

此示例将修补模块滚动到目标锚点 ( https://www.drupal.org/project/scroll_to_destination_anchors )

These are the steps to apply a patch to a module using Composer:

这些是使用Composer将补丁应用到模块的步骤:

使用Composer添加模块 (Add the module with Composer)

To download the module to our site, all we have to do is run this command in a terminal while being in the site root folder:

要将模块下载到我们的站点,我们要做的就是在站点根目录中的终端中运行以下命令:

composer require drupal/scroll_to_destination_anchors

作曲家需要drupal / scroll_to_destination_anchors

This command will download the module to /var/www/public/drupal_site/modules or /var/www/public/drupal_site/modules/contrib (if we have created this directory, which is recommended).

此命令会将模块下载到/ var / www / public / drupal_site / modules或/ var / www / public / drupal_site / modules / contrib (如果我们已创建此目录,建议使用)。

查找补丁 (Find a patch)

Finding a patch for the module is easy. It can be done from the module page (see example link above). There’s a column that says: “Issues for XXX”, in my example case “Issues for Scroll to destination anchors”.

查找模块的补丁很容易。 可以从模块页面完成(请参见上面的示例链接)。 有一列显示为:“ XXX的问题”,在我的示例中为“滚动到目标锚点的问题”。

This is the issue I was having:

这是我遇到的问题:

https://www.drupal.org/project/scroll_to_destination_anchors/issues/2916996

https://www.drupal.org/project/scroll_to_destination_anchors/issues/2916996

And there’s a patch for it already:

并且已经有一个补丁:

https://www.drupal.org/files/issues/2018-04-18/stda-working_for_84-2916996-8_0.patch

https://www.drupal.org/files/issues/2018-04-18/stda-working_for_84-2916996-8_0.patch

应用补丁 (Apply the patch)

To apply the patch to the contrib module, we have to edit the composer.json file in the site root folder.

要将补丁应用到contrib模块,我们必须在站点根文件夹中编辑composer.json文件。

Then look for this line: “enable-patching”: “true”,

然后查找以下行: “ enable-patching”:“ true”,

Then add something like this after it:

然后在其后添加如下内容:

"patches": {    "drupal/scroll_to_destination_anchors": {        "Working for 8.4?": "https://www.drupal.org/files/issues/2018-04-18/stda-working_for_84-2916996-8_0.patch"    }}

This is the structure:

结构如下:

"patches": {    "drupal/module_machine_name": {        "Description of the issue": "Path to patch in Drupal.org"    }}

And you will end up with something like this:

您将得到如下结果:

"extra": {    "drupal-scaffold": {        "locations": {            "web-root": "./"        }    },    "installer-paths": {        "core": [            "type:drupal-core"        ],        "libraries/{$name}": [            "type:drupal-library",            "type:bower-asset",            "type:npm-asset"        ],        "modules/contrib/{$name}": [            "type:drupal-module"        ],        "profiles/contrib/{$name}": [            "type:drupal-profile"        ],        "themes/contrib/{$name}": [            "type:drupal-theme"        ],        "drush/Commands/contrib/{$name}": [            "type:drupal-drush"        ],        "modules/custom/{$name}": [            "type:drupal-custom-module"        ],        "themes/custom/{$name}": [            "type:drupal-custom-theme"        ]    },    "drupal-core-project-message": {        "include-keys": [            "homepage",            "support"        ],        "post-create-project-cmd-message": [            "<bg=blue;fg=white>                                                         </>",            "<bg=blue;fg=white>  Congratulations, you’ve installed the Drupal codebase  </>",            "<bg=blue;fg=white>  from the drupal/legacy-project template!               </>",            "<bg=blue;fg=white>                                                         </>",            "",            "<bg=yellow;fg=black>Next steps</>:",            "  * Install the site: https://www.drupal.org/docs/8/install",            "  * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",            "  * Get support: https://www.drupal.org/support",            "  * Get involved with the Drupal community:",            "      https://www.drupal.org/getting-involved",            "  * Remove the plugin that prints this message:",            "      composer remove drupal/core-project-message"        ]    },    "installer-types": [        "bower-asset",        "npm-asset"    ],    "patchLevel": {        "drupal/core": "-p2"    },    "enable-patching": "true","patches": {        "drupal/scroll_to_destination_anchors": {            "Working for 8.4?": "https://www.drupal.org/files/issues/2018-04-18/stda-working_for_84-2916996-8_0.patch"        }    }}

Then, all we have to do is run:

然后,我们要做的就是运行:

composer update

作曲家更新

And that’s it. The module will be downloaded and the patch automatically applied.

就是这样。 该模块将被下载并自动应用补丁。

  • 登录或注册以发表评论
内容类型分类
技术文章
文章归类
drupal

文章标签

  • drupal 8

评论

文章标签

Excel
CSS
ubuntu
php
vim
VPN
五笔
Linux
command
HTML
drupal 8
centos
drupal 7
composer
Mysql
模块(module)
drush
Drupal
JavaSrcipt
apache
英语
drupal 9
nerdtree
network
果树种植
surround
drupal10
SEO
主题(theme)
二进制
更多

相关文章

  • 因权限问题导致drupal cms 无法正常安装,那么该如何解决这个问题
  • kvm虚拟机启动失败:default网络未激活
  • ubuntu 安装kvm 虚拟机
  • foreach 是 PHP 循环语句使用方法
  • implode() 函数的定义和用法
  • Drupal 11 主题制作教程
  • 检查 Composer 是否为官方源
  • 在 Drupal 中权重(Weight)是怎样排序的
  • 解决 Drupal 主题缺失问题
  • 为什么学习php 会一边学,一边忘
RSS源

友情链接 网站地图 版权信息 联系我们 网址导航 社区

Copyright © 2019 - 2021 你行网 版权所有  粤ICP备19072650号-1