【问题标题】:How to install custom module and its dependencies with composer in Drupal 8如何在 Drupal 8 中使用 composer 安装自定义模块及其依赖项
【发布时间】:2019-02-11 07:42:27
【问题描述】:

您好,我正在尝试使用 composer 设置我的新 Drupal 8 站点,但遇到了一些问题。

我尝试按照here 的指南设置站点站点,并且能够成功设置站点。

之后,我尝试安装托管在 Bitbucket 上的自定义模块,并且可以使用 composer 下载该软件包,但问题是该模块有一些其他贡献的模块依赖项,但依赖项模块没有与自定义模块。

我按照here 的指南将composer.json 文件与依赖项一起添加到了我的自定义模块中,但在运行composer require custom/custom_module 之后,只安装了自定义模块,但没有安装依赖项。

我的根目录 composer.json 文件存储库部分如下所示:

"repositories": [
    {
        "type": "composer",
        "url": "https://packages.drupal.org/8"
    },
    {
      "type": "package",
      "package": {
        "name": "custom/custom_module",
        "version": "master",
        "type": "drupal-custom-module",
        "source": {
          "type": "git",
          "url": "git@bitbucket.org:username/custom-module.git",
          "reference": "master"
        }
      }
    }
],

自定义模块中的 composer.json 文件如下所示:

{
    "name": "custom/custom_module",
    "description": "This is a Custom Module with Different functionalities.",
    "type": "drupal-custom-module",
    "minimum-stability": "dev",
    "require": {
        "drupal/restui": "~1.16"
    }
}

我也将"drupal/restui": "~1.16" 更改为"drupal/restui": "^1.16",但没有成功。

我什至尝试在自定义模块目录中运行composer update,因为我不确定依赖项是否会与自定义模块一起安装。

在自定义模块目录中运行composer update 后出现以下错误:

您的需求无法解析为一组可安装的软件包。

问题 1 - 请求的包drupal/restui在任何版本中都找不到,re可能是包名的拼写错误。

潜在原因: - 包名中的拼写错误 - 根据您的最低稳定性设置,该软件包在足够稳定的版本中不可用 有关更多详细信息,请参阅https://getcomposer.org/doc/04-schema.md#minimum-stability。 - 这是一个私有包,您忘记添加自定义存储库来查找它

阅读https://getcomposer.org/doc/articles/troubleshooting.md了解更多常见问题。

但是在 Drupal.org 我可以找到那个版本的模块here

请帮我解决问题。

【问题讨论】:

  • 尝试使用vcs 存储库而不是package - package 具有人的局限性,并且经常使人感到困惑。

标签: drupal composer-php drupal-modules drupal-8


【解决方案1】:

试试这个:

根 composer.json 部分

 "repositories": [
    {
      "type": "composer",
      "url": "https://packages.drupal.org/8"
    },
    {
      "type": "vcs",
      "url": "git@bitbucket.org:username/custom-module"
    }
  ],

具有两个模块作为依赖项的模块 composer.json 示例

{
  "name": "username/custom-module",
  "version": "1.2.3",
  "type": "drupal-custom-module",
  "description": "Custom module",
  "keywords": ["Drupal"],
  "license": "GPL-2.0+",
  "minimum-stability": "dev",
  "repositories": [
    {
      "type": "composer",
      "url": "https://packages.drupal.org/8"
    }
  ],
  "require": {
    "drupal/admin_toolbar": ">=1.2",
    "drupal/chosen": ">=2.6"
  }
}

【讨论】:

  • 感谢您的回答,但还是同样的问题,依赖模块没有被渲染。
  • @miststudent2011 “不被渲染”是什么意思?没有下载?
  • @miststudent2011 我发布的结构应该是正确的,但它可能是别的东西。您能否分享您更新的代码(项目和模块编写器?)。您也可以尝试清除作曲家缓存(composer clear-cache)并在您再次请求后确认您的模块不在vednor文件夹中吗?
猜你喜欢
  • 2017-04-14
  • 2019-09-28
  • 2019-11-02
  • 2010-12-25
  • 1970-01-01
  • 1970-01-01
  • 2013-12-05
  • 1970-01-01
  • 2015-01-24
相关资源
最近更新 更多