跳转到主要内容
你行网

Main navigation

  • 首页
  • 文章
  • 教程
  • 视频
  • 下载
  • 社区
  • 网站导航
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 8
  • 登录或注册以发表评论

评论

相关文章

drupal8 配置cron任务
迁移到您的搜索引擎优化的Drupal 8网站
Drupal 8的https域名重定向优化301重定向
如何给drupal 8 修复打补丁
drupal 8 网站遇到意外错误,请稍后再试。
drupal 8 使用flippy模块实现文章上一篇下一篇功能解决方案
drupal 8 安装提示未启用php apcu 和 PECL uploadprogress 插件
drupal 8 安装提示信任主机设置
drupal 8 安装提示权限安全风险
drupal 8 安装提示缺少php opcode 缓存插件
drupal 8 安装提示配置文件不存在
drupal 8 安装提示没有files 文件
drupal 8 可信主机设置
Drupal 8.7.6 安装详解图文教程

文章标签

CSS
Excel
ubuntu
php
五笔
vim
Linux
HTML
command
drupal 7
composer
centos
Mysql
drupal 8
模块(module)
VPN
drush
JavaSrcipt
apache
drupal 9
英语
Drupal
SEO
nerdtree
network
果树种植
surround
drupal10
主题(theme)
phpmyadmin
ssh
权限
yum
二进制
声音
ssl
selinux
HTML5
用户
Dreamweaver
password
flameshot
颜色
翻译
uploadprogress
DDEV
视图(views)
firewalld
kernel
gzip
快捷键
xdebug
错误
ckeditor
C语言
mbstring
简介
源地址
php扩展
电脑基础
certbot
git
apt
压缩解压
电子秤
邮件验证
表单
WireGuard
httpd
breadcrumb
AI
superfish
diff
重定向
摄影
网站备份
tagclouds
docker
短信验证
csharp
java
adsense
drupal9
电脑技巧
simple_adsense
算法
RSS
youtube
版本号
JavaScript
badblocks
端口
cookie
VUE
网站运营
计算机基础
gimp
form
mod_expires 模块
zip
nginx
http验证
重定向,301
curl
ip
netstat
input
赚钱
dns
RFID
标签优化
drupal11
maven
drupal 11
npm
哈希值
字段
更多
RSS源
本站由阿里云强力驱动,幸运券优惠链接
Copyright © 2019 - 2021 你行网 版权所有  粤ICP备19072650号