Drupal is one of the world's most widely used Content Management System. It is mainly used to create your own website and publish it using an online webhost. Drupal 8, its latest release, takes the lead over Drupal 7 since it brought along with it a lot of changes. Drupal 8 is also very fast and flexible.
Below are few steps you need to follow to create a module in drupal. A module is basically a simple page where you can add your own features by using Controllers, which we will later on in this article.
ii) A routing.yml file - Routing File
iii) A Controller
Building the module
A module needs to have the .info.yml extension. This file will contain important information such as:
(i) name of the module
(ii) a description of what the module can do
(iii) the type, which can be module, profile or theme
(iv) package, which should be set to Custom if you are designing your own
(v) core, which will determine which version of drupal will be accepted
There are also several more information stored in a info.yml file, but for a simple hello world module, these should be sufficient.
At this point, your module is created, and you can effectively enable it by going to Extend and searching for your module name, in our case, Hello World. But, this module, although enabled, would not do anything, since its path and Controller does not exist yet.
Building the routing

A routing file needs to have the .routing.yml extension. This file contains:
(i) a path specified to register the module
(ii) defaults properties, that contains the controller path
(iii) requirements, storing permissions of who can access that particular module
The first line states the name of the module and the path is simply the link that is used by the client to generate the module. Under defaults is the controller settings.
Drupal\hello_world\controller -> is the path that stores the Controller HelloWorldController and hello is the name of the method inside the controller.
You can add more options to your routing file. See this documentation
Building the Controller
The controller file contains the main methods that is called whenever a user requests the page. In our case, the method is hello(). The controller needs to be created inside src/controller.
The namespace states the path of where the Controller is located. The class HelloWorldController here, contains one method/function hello that returns an array with the contents of the modules.
After clearning all the cache, which can be done either by going to Configurations >> Performance >> Clear all cache, or by installing Drush, which is very helpful since you can simply clear cache by running "sudo drush cache-rebuild", inside your drupal website directory. See installation documentation for Drush.
After that, you module should be up and running.
Below are few steps you need to follow to create a module in drupal. A module is basically a simple page where you can add your own features by using Controllers, which we will later on in this article.
Click here to check out my blog post on how to install Drupal using composer.
Structure of files
i) An info.yml file - Moduleii) A routing.yml file - Routing File
iii) A Controller
Building the module

A module needs to have the .info.yml extension. This file will contain important information such as:
(i) name of the module
(ii) a description of what the module can do
(iii) the type, which can be module, profile or theme
(iv) package, which should be set to Custom if you are designing your own
(v) core, which will determine which version of drupal will be accepted
There are also several more information stored in a info.yml file, but for a simple hello world module, these should be sufficient.
At this point, your module is created, and you can effectively enable it by going to Extend and searching for your module name, in our case, Hello World. But, this module, although enabled, would not do anything, since its path and Controller does not exist yet.
Building the routing

A routing file needs to have the .routing.yml extension. This file contains:
(i) a path specified to register the module
(ii) defaults properties, that contains the controller path
(iii) requirements, storing permissions of who can access that particular module
The first line states the name of the module and the path is simply the link that is used by the client to generate the module. Under defaults is the controller settings.
Drupal\hello_world\controller -> is the path that stores the Controller HelloWorldController and hello is the name of the method inside the controller.
You can add more options to your routing file. See this documentation
Building the Controller
The controller file contains the main methods that is called whenever a user requests the page. In our case, the method is hello(). The controller needs to be created inside src/controller.
The namespace states the path of where the Controller is located. The class HelloWorldController here, contains one method/function hello that returns an array with the contents of the modules.
After clearning all the cache, which can be done either by going to Configurations >> Performance >> Clear all cache, or by installing Drush, which is very helpful since you can simply clear cache by running "sudo drush cache-rebuild", inside your drupal website directory. See installation documentation for Drush.
After that, you module should be up and running.