Drupal Modules: A Beginner’s Guide (2021)

Drupal websites are built with and powered by, Drupal modules. There are three different types of Drupal modules – core, contributed, and custom. Core modules are included with your original Drupal download and can be turned on or off without the need to download any additional components. Contributed modules must be downloaded independently and added to your website. Examples of contributed modules are Panels, Views, or Metatag. Custom Drupal modules are modules you write yourself. This requires extensive knowledge of Drupal’s API and PHP Programming. Modules are the easiest way to add new and useful features to your Drupal website without directly touching the codebase. The best part about Drupal modules? They’re all free!

What is a Module?

A Drupal module is a collection of files that contain code that extends Drupal functionality by adding new features. The code is built to execute within the context of the site, meaning it can use all the functions and access all variables and structures of the Drupal core. 


Where Are Modules Found?

The quickest (and most cost effective) way to extend Drupal’s functionality beyond core is to employ contributed modules. Contributed modules are packages of code created by the Drupal community and they can be downloaded and added to your website for free. Drupal’s website catalogs an exhaustive list of available modules, and these bundles of code can be downloaded directly from the module’s page on drupal.org. They are available in both tar.gz and .zip format, both of which can be unpacked after adding the module to your web server.

 

Why Are Modules Useful?

Modules are packages of code that enhance and extend the functionality of a base Drupal installation. The Drupal package is referred to as Drupal Core, and Drupal 9 comes prepackaged with over seventy core modules and nine themes. All of these core modules can be viewed in the /modules directory. This collection of core modules was vetted by the Drupal community in advance of Drupal 7’s release (January 2011) and they were determined to contain the base functionality most Drupal site administrators would need. Any functionality beyond this can be added by a developer or through contributed modules.

Image
Core Modules

How Do I Add Modules to My Website?

There are two ways to add modules to your website – using Composer or Drush (Composer is recommended by Drupal).

Composer

When adding a module to your codebase through Composer, first, make sure you have Composer installed and ready to go. Above your docroot directory, you should see a composer.json file. According to Drupal’s website, you should enter the following command below:

Image
Code 1

Finally, send the changes to your code repository and commit your final changes. Once the module is added, make sure to enable it.

Drush

When adding a module using Drush, first, navigate to your website’s docroot directory through a command prompt window. Then, you should run the following command:

Image
Code 2

Finally, you can complete the configuration after signing in as an administrator and clicking “Extend”. After finding the module you would like to enable, select it and click install.

 

Custom Modules

Drupal 8 and Drupal 9 allow you to create your own modules, but this will require extensive knowledge in PHP programming and Drupal’s API documentation.

Drupal Modules: A Beginner’s Guide (2021)

This feature allows you to create custom configurations, field types, field widgets, and field formatters. The code for this is explained in detail on Drupal’s website, which can be reached here: https://www.drupal.org/docs/creating-custom-modules

 

Summary

Core modules are the backbone upon which your Drupal website is built and contributed modules work in tandem with the backbone to complete your website's skeletal structure. With an understanding of what modules are and why they’re useful, as well as how to install and configure them, you’re well on your way to customizing a Drupal website to fit all of your organization’s needs.