Drupal 8 custom module structure
Drupal 8 has been rewritten from scratch and it heavily uses OOP. And this affects all the way we write code for Drupal 8, be it a custom module for your project or a contributed module that you want to publish on drupal.org
Let us dive into the details and learn how to write a custom module for Drupal 8!
In this first article of the ‘Drupal 8: Writing your first Drupal 8 custom module’ series, we will explore the details of the info.yml file.
The info file
With slight modifications, the info file is almost identical to previous versions of Drupal. However, in Drupal 8, it is known as info.yml and a few extra parameters/instructions/routines for Drupal 8
In Drupal 8, info.yml file takes following details/routines:
type*: Is this a module or theme or even a distribution/profile? Allowed values: string module|theme|profile
name*: Name of your custom module/theme/distribution/profile Allowed value: string [A human readable name which will be displayed on Modules list page] GeoBlocker
description*: some descriptive text about your custom code. Allowed value: string [details about what your module offers]
core*: What Drupal core version this custom code targets. Allowed value: 8.x (Post Drupal core 8.8, this routine is no longer required)
package: In what group you want to put this custom code in. If you do not specify this routine, Drupal puts your custom code under ‘others’ on modules list page. Allowed value: string Geo
core_version_requirements: Specifically used to denote that your custom code/module is compatible with Drupal 9 and can be used on a Drupal 9 website without modifying code.
Allowed value: ^8 || ^9
configure: If your module offers a configuration page, you need to provide reference to relative path to the configuration page here, as in your routing.yml file.
* required routine
Here is an example of actual Drupal 8 / 9 module info.yml file
description: "Restricts or allows access to the website, or to a subset of nodes, in regards of user's country of origin."
core_version_requirement: ^8.8 || ^9