Module

The installable unit of Drupal code. Core ships some, Drupal.org hosts contributed ones, and a site team can write its own custom ones.

Learn DrupalDrupal glossary

A module is the unit of extension in Drupal: a folder of PHP, JavaScript and CSS files that adds features to a site. A module is recognized by its .info.yml file. It does nothing until you install it, and turning it off again is called uninstalling it. User accounts, basic content and lists all come from modules.

How modules work in Drupal 11

The User Guide sorts modules into three groups. Core modules come with the download, among them User, Node, Field, Menu UI and Views. Contributed modules are downloaded from Drupal.org. Custom modules are written for one site; see custom module.

Drupal finds modules in the /modules directory, which is preferred, or in a /sites/*/modules directory, and searches subdirectories. Putting Drupal.org downloads in /modules/contrib and project code in /modules/custom is a common practice, not a requirement.

The .info.yml file has three required keys: name, type (the value module) and core_version_requirement. Optional keys include description, package, dependencies and configure. In the Drupal 11.4 code, the info parser throws an exception for a module outside core that lacks core_version_requirement.

A module adds behavior through the usual parts: classes in src/, YAML files for routes, permissions and services, and hooks, which core's hooks topic calls one way for a module to alter the behavior of core or of another module.

Getting a module on a site takes two steps. First add the code, which Drupal.org recommends doing with Composer. Then install it. Installing enables the module and makes its database configuration changes. The Extend page at /admin/modules and drush pm:install both do this. Core modules skip the first step because they are already in the download.

Example

To add Search API and its database backend, run Composer and then Drush:

composer require drupal/search_api
        drush pm:install search_api search_api_db

The same install can be done by ticking both modules on the Extend page. After that, set permissions at /admin/people/permissions.

Common mistakes

  • Forgetting permissions. Non-administrators get no access to a new module by default, so it can look broken to editors who simply lack access.
  • Reusing a name. A module's machine name must be unique across every module, theme, theme engine and installation profile on the site. It starts with a letter and uses lowercase letters, digits and underscores.

For marketing and content teams

When you ask for a feature, such as better forms or a calendar, the answer can be "install this module". Ask which kind it is: a core module needs no download, a contributed module is maintained on Drupal.org, and a custom module is code your team maintains from now on. Installing needs the administer modules permission, so it is a developer or administrator task.

With DXPR

DXPR Builder is a module. Its Drupal.org project page gives the install command composer require drupal/dxpr_builder and asks you to enable it afterwards. See DXPR Builder.

Sources

Questions about Drupal modules

Use the Uninstall tab of the Extend page at /admin/modules/uninstall, or drush pm:uninstall, which also uninstalls the modules that depend on the one you name. Drupal has no separate disable step. Uninstalling removes the module's configuration, and you may first have to delete data that the module provides.

The Drupal User Guide says that each installed module adds to the time needed to generate pages, and that it is a good idea to uninstall modules you do not need. Review the Extend page from time to time and remove what nobody uses.

Related terms

All Drupal terms from A to Z