Extra Block Types (EBT) - New Layout Builder experience❗

Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.

Demo EBT modules Download EBT modules

❗Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll

Articles

14/04/2025, by Ivan

Drupal 8 uses a range of advanced PHP features and sophisticated third-party libraries to provide third-party developers with the most advanced API of any available CMS. While experienced Drupal 7 developers may notice some significant changes, much of the core structure remains familiar.

If any of the material presented in the step-by-step D8 module developer guide is new to you, the resources below may help. However, exhaustive knowledge is not required to proceed to the D8 module walkthrough.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

14/04/2025, by Ivan

Before You Begin

If you want PHP to help identify your errors on a test site, try the settings described here: Displaying all errors during development.

Name Your Module

The first step in creating a module is to choose a “short name” or machine name for it. This machine name will be used in several files and functions of your module, and the Drupal core uses it programmatically to reference your module.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

14/04/2025, by Ivan

In the following subsections of the guide, we will create examples of various parts of a Drupal site, such as a custom page, block, entity, field, etc. All examples start with the module folder and the .info.yml file, and with just these two items the module will appear on the extended Drupal 8 administration page or can be activated directly using Drush.

This subsection will guide you through the process of getting started by creating, naming, and properly placing the .info.yml file, which will become the starting point for each new module you create.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

14/04/2025, by Ivan

When developing custom modules, there are several scenarios where the developer is required to add a composer.json file to the module. Some of these scenarios depend on whether the custom module is intended to be shared with the community as a project on drupal.org.

If a module developer wants to use a PHP library hosted on packagist.org, they must add a composer.json file to their project.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

14/04/2025, by Ivan

In the next section, we will look at creating a simple module. There is a long-standing tradition that the first program you write in any new system displays "Hello World!" on the screen.

Although Drupal is one of the boldest and most progressive open source projects, it is also deeply rooted in long-standing scientific and technical traditions.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

14/04/2025, by Ivan

The content() function in the HelloController class will return markup text when the routing system calls the page.

In your module folder, you should have the standard PSR-4 folder structure /src/Controller, and inside this folder, you should have the controller file HelloController.php.
Thus, your controller file will be located at
/src/Controller/HelloController.php

You have the following code in the HelloController.php file:

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

14/04/2025, by Ivan

Return to the root folder of your module where the .info.yml file is located, add a new file named hello_world.routing.yml, and add the following content to it:

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

13/04/2025, by Ivan

Now that we've created a placeholder for our module's settings page, let's add a menu link. The instructions below show how to create a menu link for the hello_world module under the “Development” section on the “Admin > Configuration” page (http://example.com/admin/config).

In the root folder of your module, create a new file named hello_world.links.menu.yml and add the following:

Source URL:

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

13/04/2025, by Ivan

This guide continues with the Hello World module, demonstrating how to gradually add custom blocks (and more).

If you're feeling adventurous, you can jump straight to the Examples module. The Examples module contains many more code samples used in this guide. If you're new here, keep following this tutorial and check out the Examples modules when you're ready to dive deeper.

Source URL:

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.