您的位置:首页 > 其它

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

2016-02-16 18:17 274 查看
  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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Drupal8开发教程