Create custom module

  1. Create new folder under Module folder with the module name. eg: Module/custommodule
  2. Create 3 file under custommodule as below: -

custommodule.info.yml
Place this code into above file
   Name: custommodule
   Type: module
   Description: 'custommodule'
   Package: Custom
   Core: 8.x


custommodule.module
No need to give any code into above file -- leave it blank


custommodule.routing.yml
Place this code into above file
   custommodule.content:
     path: '/custommodule'
     defaults:
       _controller:
   'Drupal\custommodule\Controller\custommodule::content'
       _title: 'custommodule'
     requirements:
       _permission: 'access content'


3. Create controller directory: custommodule > src > controller
4. Under controller folder, create file name custommoduleController.php

Place this code into above file

   <?php
   namespace Drupal\custommodule\Controller;
   class custommoduleController {
   public function custommodule() {
   return array(
   ‘#title’ => 'custommodule’,
   ‘#markup’ => ‘Content for custommodule.’
   );
   }
   }


5. Enable the custommodule


Note: Replace custommodule with your module name

That is the very basic custom module for practice purpose, but we can create more complex module according to our need.

Source: -


YourTube: -