Creating the .info.yml file for module metadatafor Drupal 8 , 9 , 10 , and 11

Last updated :  

Following our setup of the module folder structure, the next critical step is to create the .info.yml file. This file acts as the module's metadata signature, informing Drupal of its existence and providing essential details like name, description, type, and dependencies.

Understanding the .info.yml File

The .info.yml file is crucial for any Drupal module. Written in YAML, a human-readable data serialization format, it defines various properties of the module. Drupal uses this metadata to manage modules within the system, ensuring proper hook-ups and performance.

The Basic Structure of a .info.yml File

Let’s break down the essential elements you’ll include in the hello_world.info.yml file. Navigate to your module directory modules/custom/hello_world and create a new file named hello_world.info.yml.

name: 'Hello World'
type: module
description: 'A simple hello world module for learning purposes.'
package: Custom
core_version_requirement: ^9.3 || ^10.0
version: '1.0.0'
        
  • name: This is the human-readable name of your module. It's displayed in the module list within the Drupal admin interface.
  • type: Specifies the type as "module". It helps Drupal categorize it among other extensions.
  • description: A brief description of what your module does. This information is useful for administrators reviewing module functionality.
  • package: Dictates the grouping under which your module appears in the module listing page. "Custom" is a common package name for custom modules.
  • core_version_requirement: Indicates which major versions of Drupal's core the module is compatible with.
  • version: Assigns a version number to your module, following semantic versioning practices.

This basic setup configures your module metadata, allowing Drupal to load it appropriately.

Best Practices for .info.yml File

Maintaining best practices while creating your .info.yml file ensures sustainability and clarity:

  • Consistency: Keep naming conventions consistent throughout your configuration files.
  • Documentation: Update the description and version as the module evolves, providing a clear history and expectations for users.
  • Compatibility: Regularly verify and update the core_version_requirement to maintain compatibility with future Drupal updates.

Being meticulous with these practices can lead to smoother module management and lesser conflicts.

Verifying the Module

With the .info.yml file in place, verify your module within the Drupal admin interface:

  1. Log in to your Drupal admin dashboard.
  2. Navigate to Extend from the admin menu.
  3. Locate your module within the list, using the package name or module name filter.
  4. Enable the module by checking the box next to its name and clicking Install.

If everything is configured correctly, you should see your "Hello World" module listed and ready for enabling and use. If not, double-check the YAML syntax and directory placement.

Conclusion

In this lesson, we've covered the creation and configuration of the .info.yml file, a linchpin in registering your custom module with Drupal. Understanding and setting these properties accurately is essential for smooth operation within the Drupal framework.

Next, we will explore Adding dependencies in .info.yml (core, contrib, or custom modules). This will enhance your module’s capability by defining its interactions with other modules. Keep progressing with us!