Extending and altering Drupal in Drupal 9
Same name and namespace in other branches
- 8 core/core.api.php \extending
Overview of extensions and alteration methods for Drupal.
Types of extensions
Drupal's core behavior can be extended and altered via these three basic types of extensions:
- Themes: Themes alter the appearance of Drupal sites. They can include template files, which alter the HTML markup and other raw output of the site; CSS files, which alter the styling applied to the HTML; and JavaScript, Flash, images, and other files. For more information, see the Theme system and render API topic and https://www.drupal.org/docs/theming-drupal
- Modules: Modules add to or alter the behavior and functionality of Drupal, by using one or more of the methods listed below. For more information about creating modules, see https://www.drupal.org/docs/creating-custom-modules
- Installation profiles: Installation profiles can be used to create distributions, which are complete specific-purpose packages of Drupal including additional modules, themes, and data. For more information, see https://www.drupal.org/developing/distributions.
Alteration methods for modules
Here is a list of the ways that modules can alter or extend Drupal's core behavior, or the behavior of other modules:
- Hooks: Specially-named functions that a module defines, which are discovered and called at specific times, usually to alter behavior or data. See the Hooks topic for more information.
- Plugins: Classes that a module defines, which are discovered and instantiated at specific times to add functionality. See the Plugin API topic for more information.
- Entities: Special plugins that define entity types for storing new types of content or configuration in Drupal. See the Entity API topic for more information.
- Services: Classes that perform basic operations within Drupal, such as accessing the database and sending email. See the Dependency Injection Container and Services topic for more information.
- Routing: Providing or altering "routes", which are URLs that Drupal responds to, or altering routing behavior with event listener classes. See the Routing and menu topic for more information.
- Events: Modules can register as event subscribers; when an event is dispatched, a method is called on each registered subscriber, allowing each one to react. See the Events topic for more information.
*.info.yml files
Extensions must each be located in a directory whose name matches the short name (or machine name) of the extension, and this directory must contain a file named machine_name.info.yml (where machine_name is the machine name of the extension). See \Drupal\Core\Extension\InfoParserInterface::parse() for documentation of the format of .info.yml files.
File
- core/
core.api.php, line 1237 - Documentation landing page and topics, plus core library hooks.