Last updated October 25, 2014. Created on May 21, 2013.
Edited by batigolix, george.plescan, bbinkovitz, Kristen Pol. Log in to edit this page.

Main topic described: project metadata

An essential part of a Drupal 8 module, theme, or install profile is the .info.yml file (aka, "info yaml file") to store metadata about the project.

These .info.yml files are required to:

  • Notify Drupal about the existence of a module, theme, or install profile.
  • Provide information for the Drupal Web UI administration pages.
  • Provide criteria to control module activation and deactivation and Drupal version compatibility.
  • General administrative purposes in other contexts.

Example

The following is a sample .info.yml file:

name: Example Module
description: Example Module description.
package: Custom
type: module
version: 1.0
core: 8.x
dependencies:
  - node
configure: example.admin_index

The .info.yml file should have the same unique name as the .module file (if any) and reside in the same directory. For example, if your module is named "Example," and has a example.module file, then your .info.yml file should be named example.info.yml.

Example:

example/example.info.yml
example/example.module

Looking at the example info.yml file above lets take a look at each line to see what it does.

The first three lines are primarily used in the administration UI when allowing users to enable or disable your module. The name and description (both required) keys provide the text that is shown on the module administration page and the package key allows you to group like modules together. Code for example uses package: Core to group all of the modules provided with Drupal 8 together, likewise you might use package: Custom to group all of your projects custom modules together making them easier to locate and enable.

The type key, which is new in Drupal 8, is required and indicates the type of extension, e.g. module, theme or profile.

For modules hosted on drupal.org, the version number will be filled in by the packaging script, you should not specify it manually, but leave out the version line entirely.

The core key is required and specifies the version of Drupal core that your module is compatible with.

The optional dependencies key provides Drupal with a list of modules that are required in order for your module to work correctly. For example, if you're going to call code from the node module or implement a hook provided by the block module, then you would want to specify them as dependencies. This key tells Drupal that your module cannot be enabled unless its dependencies are also present and enabled. You can include core, contributed, and custom modules alike.

If the module provides one or more configuration pages in the administration section, then the configure key can be used to specify the route (see a short intro to routing later in this quickstart example) for the administration page.

In addition to the properties shown in the example you can also specify hidden: true which will hide your module from the module list on the Extend page (/admin/modules). You might find it useful to hide a module if, for example, it only contains tests for the testing framework to use, or it is a sub-module that's only intended to serve as an example for developers who need to implement the main module's API. To avoid clutter on the Modules list, you can choose to hide them.

Debugging .info.yml files

Module is not listed on admin/modules

  • Ensure the info file is named modulename.info.yml and is located in the root of the module directory.
  • Ensure that the file has the line:
    type: module
  • Ensure the module name starts either with a letter or an underscore. Excerpt from the PHP documentation:

    Function names follow the same rules as other labels in PHP. A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.

Module is listed on admin/modules but its checkbox is disabled.

  • Make sure that the core compatibility is set to 8.x:
    core: 8.x
  • Ensure that all the module dependencies are available. You can expand the module information to see which requirements are missing:
    expand_requirements.png
    Note that some modules have been moved out of Drupal 8 core, whereas other contributed modules have been moved into core or replaced by new core modules.

Module description is empty

  • Remember that the description key is required.
    description: Example Module description.

See also

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.