Drupal8开发教程:认识.info.yml文件
2016-02-02 00:00
218 查看
YAML 文件是新引入的重要项目文件,在 Drupal 8 中,无论是模块、主题还是安装配置文件,都需要 .info.yml 文件来为其存储项目相关的基础信息。
在 Drupal 中,.info.yml 文件通常会被作为以下用途进行使用:
向 Drupal 声明模块、主题、安装配置文件的存在情况
向 Drupal Web管理界面提供信息
提供模块启、禁用条件以及版本兼容性信息
其它管理用途
代码中的前三行信息会被用于模块管理界面,用户在启用、禁用模块时可以看到这些信息。其中 name 和 description为必填项,分别代表模块的名称与描述。
package 为选填用于设置模块的分组信息。
type 是 Drupal 8中新加入的“必填”信息,用于声明项目的类型,如module, theme或profile(模块、主题或安装配置包)
core 用于设置Drupal内核的版本信息,以便Drupal确认此项目所兼容的Drupal版本。
YAML文件中的配置项都足够语义化,单从字面便能理解其含义。如果曾有过 Drupal 相关的开发经验,理解 Drupal 8 中的 YAML 配置文件就更简单了。
在 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文件
- Drupal8开发教程:认识.info.yml文件
- 关于@Configuration和@Bean的新发现
- Android 判断签名MD5——JNI实现
- nginx源码修改之stub_status
- Mac PHP连接MySQL报错"No such file or directory"
- 浅谈Android五大布局——LinearLayout、FrameLayout和AbsoulteLa
- java.lang.*不用我们导入,编译器会自动给我们导入的,,,这个包是默认导入的。
- [深入理解Android卷一全文-第八章]深入理解Surface系统
- OpenGL ES之GLSurfaceView学习一:介绍
- 爬取贴吧帖子
- 常用脚本之本件
- 常用脚本文件之批处理
- ABBYY FineReader 12完整功能列表汇总(二)
- 设置SVN忽略文件和目录(文件夹)
- how to check logcat by specify tag
- mongodb 3.0 使用mongodump、mongorestore数据迁移
- gatling简单使用说明
- CentOS 6.6 内核升级
- 企业网盘不仅只是存储