Drupal8开发教程:认识.info.yml文件

  YAML 文件是新引入的重要项目文件,在 Drupal 8 中,无论是模块、主题还是安装配置文件,都需要 .info.yml 文件来为其存储项目相关的基础信息。

在 Drupal 中,.info.yml 文件通常会被作为以下用途进行使用:

  • 向 Drupal 声明模块、主题、安装配置文件的存在情况
  • 向 Drupal Web管理界面提供信息
  • 提供模块启、禁用条件以及版本兼容性信息
  • 其它管理用途

 

Hello World 示例

  以下是一个简单的 hello_world.info.yml 文件,你可以在本地模块目录(/modules/custom 或 /sites/all/modules/custom)下新建 hello_world 目录,并将包含下方内容到 hello_world.info.yml 文件放置到模块目录中:

name: Hellow World Module
description: Creates a page showing “Hello World”
package: Example

type: module 
core: 8.x

  • 代码中的前三行信息会被用于模块管理界面,用户在启用、禁用模块时可以看到这些信息。其中 name 和 description为必填项,分别代表模块的名称与描述。
  • package 为选填用于设置模块的分组信息。 
  • type 是 Drupal 8中新加入的“必填”信息,用于声明项目的类型,如module, theme或profile(模块、主题或安装配置包)
  • core 用于设置Drupal内核的版本信息,以便Drupal确认此项目所兼容的Drupal版本。

 

完整示例

除了上述例子中属性设置项外,项目信息文件还包含其它一些可选的属性,具体可参考以下代码:

name: Hello World Module
description: Creates a page showing "Hello World".
package: Custom

type: module
core: 8.x

dependencies:
  - datetime
  - link
  - views

configure: hello_world.settings

hidden: true

# Note: do not add the 'version'  property yourself!
# It will be added automatically by the packager on drupal.org.
version: 1.0

  YAML文件中的配置项都足够语义化,单从字面便能理解其含义。如果曾有过 Drupal 相关的开发经验,理解 Drupal 8 中的 YAML 配置文件就更简单了。

原文标题:Drupal8开发教程:认识.info.yml文件

原文地址:http://drupalct.org/drupal-development/learn-drupal8-info-yaml-file.html

转载于:https://www.cnblogs.com/tanjede/p/5176949.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值