Table of Contents
- Backup your database
- Check my code out of Github, or create a module directory
- Create a project info YAML file
- Create the necessary subdirectories
- Write the code to display your block
- Clear the caches
- Enable the module
- Place the block module
- See the custom block on your website
- The biggest problem I encountered
- The source code
In this tutorial I’ll demonstrate how to write a simple Drupal 8 “block module.” By this I mean that I’ll show you how to write a simple Drupal 8 module that will display output in a block. When you’re done you will have created a new block that you can place in one or more theme regions.
In his book, The Universal Tone: Bringing My Story to Light, Carlos Santana writes about hearing other guitar players, and wondering with an intense curiosity how those other people got their guitars to make the sounds they made. As I thought about this I thought it was a good attitude to have in programming. For instance, if I look at an application where someone has done something really cool I try to understand, “How did they do that?”
“Perhaps the most important principle for the good algorithm designer is to refuse to be content.”
~ Alfred Aho
I was just reminded of Rubber Duck Debugging. From this Wikipedia link, “The name is a reference to a story in the book The Pragmatic Programmer in which a programmer would carry around a rubber duck and debug their code by forcing themselves to explain it, line-by-line, to the duck.” For me, my rubber duck is Albert Einstein.
“Besides a mathematical inclination, an exceptionally good mastery of one’s native tongue is the most vital asset of a competent programmer.”
~ Edsger Dijkstra
Dan Bricklin, inventor/creator of VisiCalc, the first spreadsheet program for personal computers, has created this page of historical notes and images about his work. His work came long before my interest in computers and programming, so I enjoy reading about it from a historical perspective. He shows a TI calculator and very large state diagram on this page. I remember seeing calculators like that in stores, and the work he put into the state diagram looks like a modern mind map.
If you’re into history, it’s all very cool.
“Years ago I knew little, but was comfortable using things I didn’t understand. Now I’m experienced, I fear things unless I understand them.”
“The honest answer to almost any question in software development is, ‘It depends.’”
Eric Evans, author of Domain Driven Design
Note: This is a post from 2007 that I just updated a little bit because I think there’s still some value in it.
A lot of people have written to say that it’s unfair that I think developers should never say “I’m 75% done,” or “I’m 90% done.”
So, to explain myself, here’s why I think you should never use a phrase like that: