On this page
Tutorial introduction
Intro
This guide was initially written when Drupal 8 was launched, before even Config Sync was fully fleshed out. Although there was a (slightly naive) hope for it to remain current, it grew to be very outdated in the following years - its purpose, however, has always been to flatten the learning curve for developers who wished to learn the basics of module building. With Drupal 10 out in the wild, this guide has been given a much-needed update. Read on to find out how to build a simple, but D10-compliant module, from start to finish.
Tutorial goal

What we're building in this tutorial is a module for lorem ipsum generation. Simply put, it's a module that combines random phrases to create filler text. Users can select how many paragraphs of text and how many sentences on each paragraph, hit a button and get some material for their layout needs.
The module provides a simple settings page and a block with a form for customizing how much text to generate via a Service. There's also default settings, permissions, tests and theming involved.
π loremipsum
βββ π config
β βββ π install
β β βββ loremipsum.settings.yml
β βββ π schema
β βββ loremipsum.schema.yml
βββ loremipsum.info.yml
βββ loremipsum.install
βββ loremipsum.links.menu.yml
βββ loremipsum.module
βββ loremipsum.permissions.yml
βββ loremipsum.routing.yml
βββ loremipsum.services.yml
βββ README.md
βββ π src
β βββ π Controller
β β βββ LoremIpsumController.php
β βββ π Form
β β βββ LoremIpsumBlockForm.php
β β βββ LoremIpsumForm.php
β βββ π Plugin
β β βββ π Block
β β βββ LoremIpsumBlock.php
β βββ π Service
β βββ LoremIpsumService.php
βββ π templates
β βββ loremipsum.html.twig
βββ π tests
βββ π src
βββ π Functional
βββ LoremIpsumTests.php
This is what the finished structure looks like
Don't panic
This code is simple enough to work without complications. If any change to Drupal core breaks it, please do let me know and I'll fix it ASAP. Try not to copy and paste but instead write the code as it appears: it'll help you memorize it!
Anyway, this guide is, as stated in the title, a practical one. We'll try to cover the basics and won't get into much detail about what has changed and why. Where applicable, code will be broken down into logical parts so as to include a few comments.
So without further ado, let's get started. Starting with the basic structure click through the subsections of this article for the various steps to be taken.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion