Drupal Custom Module (Basic)

Drupal has already built-in core modules that we can choose, but they do not always serve all our needs. In help with this, we can create a custom module.Under the Drupal directory, there is a module folder

Let's create a folder for our module with a name” test”. This is going to be our machine name

We need to create an info.yml file. This file includes keys and values.

This file should include a name, description of module, type, package, and core version.

Name is a human-readable name. This will appear on the "Appearance" page where the theme is activated.

Description is what we can see on the Extend page.

Package specifies a group where this module will be.

Type indicates the type of extension, i.e., "module", "theme", or "profile". For themes this should always be set to "theme". This value is case-sensitive.

Core specifies the version of Drupal core that the theme is compatible with.

Core_version_requirement  allows modules, themes, and profiles to also specify that they are compatible with multiple major versions of Drupal core.

Let's go to the extend page in Drupal. Select and install our new module.

Now we need to define a route that will activate our module. Let's create a routing file under the “test” folder.

This file includes our machine name , a path,  controller that should be accessed and permissions settings. All classes in Drupal are going to be namespaces, so we have to write the whole class name.

Under the test folder, we need to create a source folder (src), all the code will live in this folder. Under this folder create a folder controller.

In the controller folder, we are going to create “TestControll”.php ( we included this name in our routing file)

Create a class “TestControll” with  a namespace.( we included this name in our routing file)