To create a module in Drupal, follow the steps given below: Navigate to
modules/custom/
in your Drupal installation and create a new folder for your module. Example:
my_module
. Inside your module folder, create an info file,
my_module.info.yml
, which tells Drupal about your module:
Create a
my_module.module
file for your module's custom logic (if needed). This file can contain hook implementations. If your module needs custom routes (like for a page), create a
my_module.routing.yml
file:
If you added a route, create a controller in
src/Controller/MyModuleController.php
Go to the Extend menu in Drupal's admin dashboard, find your module, and enable it.