公告:

Drupal8主题开发——info.yml配置项说明

作者:star0312 / 时间:4年前 (2021/10/21) / 分类:Drupal教程 / 阅读:532 / 评论:0
#  (required)The human-readable name.
# (必须)一个可读的名称
#  This will appear on the "Appearance" page where the theme is activated.
# 当主题激活时会展示在‘外观’页面。
name: xxxxx

# (required)Indicates the type of extension, i.e., "module", "theme", or "profile".
# (必须)显示扩展的类型,如:"module"、"theme"、"profile"
# For themes this should always be set to "theme". This value is case-sensitive.
# 对于主题来说,这里必须保持为 "theme"。这个值是区分大小写的。
type: theme

# (optional)The description, displayed on the "Appearance" page.
description: 'HTML5, SASS, Responsive grid starter theme.'

# (optional)Specifies a "package" that allows you to group themes together.
# (可选)指定允许将主题分组在一起的“package”
package: Core

# (required)Specifies the version of Drupal core that the theme is compatible with.
# (必须)指定主题与之兼容的Drupal核心版本。
core: '8.x'

#  (optional)The minimum version of PHP required. Defaults to the value of DRUPAL_MINIMUM_PHP constant.
# php: 7.1.9

#  (optional)Specifies a version. For themes hosted on drupal.org,
# the version number will be filled in by the packaging script.
# Do not specify it manually, but leave out the version line entirely.
version: '8.x-1.3'

# (optional)A list of libraries (which can contain both CSS and JavaScript assets) to add to all pages where the theme is active.
# see https://www.drupal.org/node/2216195
libraries:
  - core/normalize
  - xxxxx/global

#  (optional)A collection of libraries and assets to override.
# see https://www.drupal.org/node/2216195#override-extend
# libraries-override:

# (optional)A collection of libraries and assets to add whenever a library is attached.
# see https://www.drupal.org/node/2216195#override-extend
# libraries-extend:

# (recommended)A theme can inherit the resources from another theme by specifying it as a base theme.
# It is recommended to use classy or stable (stable is the default if the key is not supplied)
#  – this makes it easier for your theme to inherit future changes in core theming.
# base theme: classy

# (optional)Indicates whether or not to hide the theme from the "Appearance" page so that it cannot be enabled/disabled via the UI.
# hidden: true

# The theme engine. Defaults to "twig".
# engine: twig

# (optional)The path to logo relative to the theme's .info.yml file.
# By default, Drupal will look for a file named "logo.svg" in the root of your theme folder and use that as the theme's logo.
# logo: images/logo.png

# (optional)The path to screenshot relative to the theme's .info.yml file.
# Screenshots should be 588 pixels wide and 438 pixels high, though they are displayed at a smaller size.
# By default, Drupal will look for a file named "screenshot.png" in the root of your theme folder and use that as the theme image on the "Appearance" page.
# screenshot: fluffiness.png

# (optional)A list of theme regions. (Note that region keys are not preceded by a dash.)
# A content region is required.
# see https://www.drupal.org/node/2469113
regions:
  header: 'Header'
  help: Help
  page_top: 'Page top'
  page_bottom: 'Page bottom'
  highlighted: Highlighted
  content: Content
  sidebar_first: 'Sidebar first'
  sidebar_second: 'Sidebar second'
  footer: 'Footer'

# (optional)A list of inherited regions to remove.
# regions_hidden:

# (optional)A list of features to expose on the theme "Settings" page.
# features:

# (deprecated)A list of stylesheets from other modules or themes to remove from all pages where the theme is active.
# Each value must be a full path relative to the docroot to resolve ambiguity when more than one file with the same name exists.
# In cases where the file is part of a library that belongs to a module or theme, a token in the form @module_or_theme_name can be used in place of the full path.
# Note that when using the token the value must be quoted because "@" is a reserved indicator in YAML.
# Note: This key is deprecated and will be removed in Drupal 9. In most cases libraries-override should be used.
# stylesheets-remove:

# (optional)A list of stylesheets to add to the CKEditor frame.
# ckeditor_stylesheets:

# Information added by Drupal.org packaging script on 2017-10-15
project: 'xxxxxxx'
datestamp: 1508096954


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 配置文件就更简单了。


stylesheets-remove:  设置的是移除自带的样式。

另外,注意每行缩进使用空格,冒号和小横线后面都有一个空格。




  • 我的QQ二维码
  • QQ群
  • 我的微信二维码
  • 微信公众号

没有评论,留下你的印记,证明你来过。


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。