Drupal 9 Course: Create & Enable Custom Module - [Part 1]

This is the beginning of a course I am writing. Click here to view what we will be building. 

So, why on earth would I need a custom module when there are contrib modules out there already? Good question! 

From time to time, you may find yourself with a request from a client that is very unique with no existing solution. That's where the "custom" comes into play. 

Module Development in Drupal 8 & 9

Step 1:

Create your module directory in the module directory, 

web/modules/custom/[your_module_name]

In this case, we will call ours "movie_directory"

movie_directory

Step 2:

Create a file and call it `movie_directory.info.yml` - If you're create a different module entirely, this file would be `module_name.info.yml`.

Add the following to the newly created file:

name: Movie Directory
description: Allow users to search for information on movies
package: CustomModules

type: module
core_version_requirement: ^8.8.0 || ^9.0

Step 3:

Lets enable our module. There are two ways we can do this.

Method 1: 

  • Open up your terminal, make sure you are in project directory and run the following command, `drush en -y movie_directory`

Method 2:

  • Log into your site, click "Extend" in the admin menu, then search for 'Movie Directory'.
  • Click the checkbox next to the module name
  • Scroll down, click the 'Install' button.

And there you have it! You've just created and enabled your custom module! Clearly, it does nothing at the moment, but as time goes on, we will be adding interesting functionality to it! I'll update this page the follow on tutorial.