programming

Drupal 8: How to write a simple custom “block module”

Table of Contents1 - Goals2 - Backup your database3 - Check my code out of Github, or create a module directory4 - Create a project info YAML file5 - Create the necessary subdirectories6 - Write the code to display your block7 - Clear the caches8 - Enable the module9 - Place the block module10 - See the custom block on your website11 - The biggest problem I encountered12 - The source code13 - Summary

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.

The “Hello, Scala” paperback is just $10

November 29, 2019: A few days ago I made the PDF version of “Hello, Scala” free, and today I made the paperback version of “Hello, Scala” available again, and reduced it’s price from $20 to just $10. Click the image below to buy the book on Amazon.

As I’ve noted before, the contents of this book are being updated and improved, and in the future it will be available as Scala Book. The HTML version of those contents are currently available on the docs.scala-lang.org site.

To be a programmer is to develop a carefully managed relationship with error

“To be a programmer is to develop a carefully managed relationship with error. There’s no getting around it. You either make your accommodations with failure, or the work will become intolerable.”

~ Ellen Ullman (via this tweet)

This quote makes me think of all those years of exception-handling with Java. I never knew there was a better way to handle errors, so I developed a strategy of letting my exceptions bubble up to the controller level (as in model/view/controller), where I would deal with them. These days I know I can use Option/Some/None in Scala, as well as Try/Success/Failure.

Programming is like this amazing puzzle game alvin November 7, 2019 - 3:25pm

“Programming is like this amazing puzzle game, where the puzzles are created by your own stupidity.” It feels like that sometimes. (Image from Rich Rogers on Twitter. Quote attributed to BradOFarrell.)

Treat your code like poetry and take it to the edge of the bare minimum

“Treat your code like poetry and take it to the edge of the bare minimum.”
~ ILYO

“I have learned magnitudes more from code I have maintained over code I have written from scratch.”
~ Viktor Klang, in this tweet

I have no idea who or what ILYO is, but I like the “poetry” part, and dislike the “bare minimum” part. As the second quote implies, code should be written so you can read it a year or two from now.

Programming languages are how programmers express and communicate ideas

“In reality, programming languages are how programmers express and communicate ideas — and the audience for those ideas is other programmers, not computers. The reason: the computer can take care of itself, but programmers are always working with other programmers, and poorly communicated ideas can cause expensive flops.”

~ Guido van Rossum, in this 2016 article

Such a disappointing feeling when a book is a letdown

I just spent 45 minutes reading a new book about a programming language I was excited to learn, then slammed it shut and said, “Poorly organized, too many words, not enough code.”

That’s always such a disappointing feeling when you have that initial excitement about a programming language (or technology), and then a book is such a letdown. (I really hope people don’t view my books that way.)