How to Create Custom module in Drupal 8
To create the custom module in Drupal 8 we have to follow the below steps:-
Custom module folder structure custom field for content type
modulename
– modulename/src
— modulename/src/Controller
— modulename/src/Controller/ModulenameController.php
— modulename/src/Plugin
— modulename/src/Plugin/Field
— modulename/src/Plugin/Field/FieldFormatter
— modulename/src/Plugin/Field/FieldFormatter/FieldFormatter.php
— modulename/src/Plugin/Field/FieldType
— modulename/src/Plugin/Field/FieldType/Fieldname.php
— modulename/src/Plugin/Field/FieldWidget
— modulename/src/Plugin/Field/FieldWidget/FieldWidget.php
-modulename/modulename.info.yml
-modulename/modulename.module
-modulename/modulename.routing.yml
-modulename/modulename.info.yml
name: modulename type: module description: Description about module. package: Custom version: 1.0 core: 8.x
———————————————-
-modulename/modulename.module
/** * @File * Example custom module for Drupal 8. * @author author name */ /** * Implementing hook_menu(). */
—————————————
-modulename/modulename.routing.yml
modulename.modulename_page: path: '/pagepath' defaults: _controller: '\Drupal\modulename\Controller\PageController::controller_function_name' _title: 'Page Title' requirements: _permission: 'access content'