Enable default configuration in your Drupal 8 module
Introduction
Much has been said—and debated—about the latest version of Drupal—Drupal 8, and one thing is certain: the way modules are built has changed significantly. There are numerous tutorials addressing the new concepts, and many of them encourage developers to stay updated as the codebase evolves.
Over the past few days, I’ve reviewed some of these tutorials, as well as the Examples module, and found an interesting use case that I hope will remain relevant for the foreseeable future!
Tutorial Goal
In this tutorial, we’ll build a module that generates lorem ipsum. In simple terms, it’s a module that combines random phrases to create placeholder text. Users can specify the number of paragraphs and sentences per paragraph, click a button, and generate some content for layout purposes.
The module will include a basic settings page and a block with a form for controlling the amount of generated text. It will also support default settings, permissions, tests, and theming.
This is what the completed module will look like.
Don’t Panic
The code is simple enough to work without complications. If a future Drupal core update breaks it, please let me know so I can fix it. Try to avoid copy-pasting—typing it out yourself will help you better understand and remember the code!
As mentioned in the title, this is a hands-on guide. The focus is on the basics, and we won’t dive deep into the reasons behind the changes in Drupal 8. Where applicable, I’ll break down each file’s code into logical parts with relevant comments.
So without further ado, let’s get started. Beginning with the basic structure, navigate through the sections of this article to learn which steps are necessary to build the module.
Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.