跳转到主要内容
你行网

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.

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

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

文章标签

  • drupal 8

评论

最新文章

  • 内容审核通知 content_moderation_notifications 模块简介
  • 调度程序 scheduler 模块简介
  • 工作流当中的草稿,已发布,很好理解,已归档是怎么理解。
  • 你行网 https://www.dwoke.com seo 关键词
  • brew 是什么命令
  • drupal 9 或 drpal 10 国内内容分享模块 Will Nice social share
  • Views Slideshow - Views Vanilla JavaScript Slideshow (VVJS) 简介和安装方法
  • drupal 11 安装statistics 统计模块
  • drupal11 扩展中找不到Statistics模块
  • drupal11 设置中的“总结摘要”和“切边的” 有什么区别

标签云

adsenseAIapacheaptbadblocksbreadcrumbbrewcentoscertbotckeditorcommandcomposercookiecsharpCSScurlC语言DDEVdiffdnsdockerDreamweaverDrupaldrupal 7drupal 8drupal 9drupal10drupal 11drushExcelfirewalldfirmwareflameshotformgimpgitgzipHTMLHTML5httpdhttp验证inputipjavaJavaScriptJavaSrciptkernelKVMLinuxmavenmbstringmod_expires 模块Mysqlnerdtreenetstatnetworknginxnpmpasswordphpphpmyadminphp扩展RFIDRSSselinuxSEOsharesimple_adsensesshsslStatisticssuperfishsurroundtagcloudstitleubuntuuploadprogressvimVPNVUEWireGuardwpsxdebugyoutubeyumzip主题(theme)二进制五笔分类术语压缩解压哈希值声音字段密码工作流快捷键摄影权限果树种植标签优化模块(module)源地址版本号电子秤电脑基础电脑技巧短信验证端口简介算法网站备份网站运营翻译英语表单视图(views)计算机基础赚钱超五类线网线邮件验证重定向重定向,301错误颜色

相关文章

  • drupal11 设置中的“总结摘要”和“切边的” 有什么区别
  • ddev 基本命令中文对照表
  • RSS源 是什么,有什么作用,如何使用。
  • 使用git 克隆drupal 开发版本和修改版本。
  • ddev 安装drush 错误和解决方案
  • 【Drupal 开发实战】告别环境配置噩梦:DDEV 使用全攻略
  • 因权限问题导致drupal cms 无法正常安装,那么该如何解决这个问题
  • kvm虚拟机启动失败:default网络未激活
  • ubuntu 安装kvm 虚拟机
  • foreach 是 PHP 循环语句使用方法
RSS源

关于我们

  • 你行网简介
  • 关于我们
  • 版权声明

网站相关

  • 社区论坛
  • 网址导航
  • 网站地图
  • 联系我们

友情链接

  • 英文学习

友情链接2

  • drupal 大学
  • 水滴间
  • 爱码网
  • Apache

友情链接3

  • MySQL
  • php
  • drupalcode

友情链接4

  • Drupal 中国
  • Drupal 老葛
  • 宁浩网
  • drupal 台湾
Copyright © 2019 - 2021 你行网 版权所有  粤ICP备19072650号-1