Monday 11 March 2019

Drupal 8 Custom Module

Create custom module with name "firstcustommodule".

Custom module folder structure
 Drupal.org custom module image


Now go to the highlighted folder(as in image), and create a folder "custom".
Now create a folder with name "firstcustommodule".




To create a custom module, there is only a single file is required, which is firstcustommodule.info.yml in current case. Please see screenshot:
Content in above mentioned file:

name: My first custom module
type: module
description: 'This is my first custom module'
core: 8.x
package: Custom 

After saving this file, this custom module will start to appear on extent page as in below screenshot:

In this image, module name and module description of module is appearing as we have given in the .info.yml file. Module machine name is the module folder name. In this case, firstcustommodule is the machine name of the module.

"firstcustommodule.module": this file is needed only if we need to implement hooks in the system. like if wee need to use hook_form_alter. Then only we need this file.


No comments:

Post a Comment