Module Filesystem

Below is a listing of some of the more commonly used files in a Drupal 8 module (themes and profiles are very similar in structure).  Most are not required unless you need the functionality that they provide.  The two required files are the ".info.yml" file and the ".module" file.

Please note that "my_module" should be replaced in all cases with the actual machine name of your module.


my_module/
  config/ 
    install/ - Configuration registry files to be loaded when module is installed
    optional/ - Configuration registry files to be loaded when module is installed
  my_module.info.yml - Module name, description, version, dependencies, etc.
  my_module.install - Custom installation, upgrade, and uninstallation code
  my_module.libraries.yml - Custom CSS/JavaScript collection definitions
  my_module.links.action.yml - Custom action links 
  my_module.links.contextual.yml - Custom contextual links 
  my_module.links.menu.yml - Custom static general menu links
  my_module.links.task.yml - Custom task links
  my_module.module - Base code for module
  my_module.permissions.yml - Custom permission definitions
  my_module.routing.yml - Custom route definitions
  my_module.services.yml - Custom service definitions
  src/ - Autoloader Class Files
    Controller/ - Custom dynamic page controllers
    Form/ - Custom configuration page definitions
    Plugin/ - Custom implementations of common Drupal components
      Block/ - Custom dynamic Drupal block definitions
      Field/ - Custom field formatters
      Filter/ - Custom input filters
      Menu/ - Custom dynamic menu items
  templates/ - Custom TWIG templates

Additional Definitions

  • Action links:  Blue buttons with white text that appear at the tops of some admin pages.

  • Contextual links:  Links shown in a pop-up box when the pencil icon is selected on any block.

  • General menu links:  Links in any menu object that appears in Structure -> Menus; A Menu plugin (src/Plugin/Menu/*.php) can be used to dynamically add links to a menu object.

  • Task links:  Tabs that show on admin pages, such as the View / Edit / Revisions tabs on node pages.

  • Service:  One example is the Breadcrumb bar service, which can be extended to let you customize the breadcrumbs that appear for specific pages.