Create the simplest custom module in Drupal

By nnevill, 4 September, 2024

To create a custom module in Drupal you have to write literally 3 lines (!!!) of code inside the info.yml file. Let's name our module "Snippets" so the snippets.info.yml will look the following way:

name: 'Snippets'
type: module
core_version_requirement: ^9.0 || ^10.0 || ^11.0

That's enough for Drupal to understand it's a custom module. Obviously, that module is useless like russian political opposition but at least it could be enabled/disabled.
It's recommended to add a description and package keys as well to describe what is your module about and to place it in the corresponding section on the "/admin/modules" page.
One more commonly used key – dependencies exists to force other modules to be installed before out module. configure key is used to specify admin settings route provided by module.

The full list of keys could be found here, but frankly you will use other keys probably once in a year or even more seldom :)

Tags

Short Description
An example of a custom module creation in Drupal with minimum effort.