Drupal 8 Module Development Guide — Create an Info File for a Module

Code With Travel
2 min readDec 25, 2019

--

in order to create a Drupal module: the info file. Each module is required to have a MODULE_NAME.info.yml.

For a module called hello_world, here are the contents of hello_world/hello_world.info.yml

name: Hello World
description: A silly example module
type: module
core: 8.x
core_version_requirement: ^8.7.7 || ^9

Now Notice that our Hello World module has been added to a new group called Other on the module administration page. As of Drupal 8.7.7, the new core_version_requirement key in *.info.yml files for modules and themes now supports Semantic Versioning.

name: My Module
type: module
core: 8.x
core_version_requirement: ^8 || ^9

The core_version_requirement key specifies that the module is compatible with all versions of Drupal 8 and 9.

If our custom Hello World module is going to require code from other modules, whether core or contributed, we can explicitly list them.

dependencies:
- webform:webform

If there are more module dependencies here is an example of that.

name: Hello World
description: A silly example module

type: module
core: 8.x

dependencies:
- drupal:node
- webform:webform
- drupal:system (>=8.2.0)

if your module needs to provide particular configuration settings that are exposed to the site administrators. The configured key in your module’s info file specifies the route that will be used to navigate to the module’s configuration settings form.

name: Hello World
description: A silly example module

type: module
core: 8.x
configure: routename
dependencies:
- drupal:node
- webform:webform
- drupal:system (>=8.2.0)

Now a complete example of info.yml.

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

type: module
core: 8.x

dependencies:
- drupal:link
- drupal:views
- paragraphs:paragraphs
- webform:webform (>=8.x-5.x)

test_dependencies:
- drupal:image

configure: hello_world.settings

php: 5.6

hidden: true

# Note: do not add the 'version' or 'project' properties yourself.
# They will be added automatically by the packager on drupal.org.
# version: 1.0
# project: 'hello_world'

For more information read https://www.drupal.org/docs/8/creating-custom-modules/let-drupal-8-know-about-your-module-with-an-infoyml-file.

Also, check the Drupal 8 custom skeleton module here. https://medium.com/@kshitij206/drupal-8-module-development-500ad361fe50

--

--

No responses yet