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.

How to install and update Drupal 7 modules from the command line with Drush

As a note to self, I learned today that you can install Drupal 7 modules from the command line with this Drush command:

drush en module_name

such as:

drush en smtp

You can also update Drupal 7 modules with Drush. For instance, I just ran these commands on a Drupal 7 website:

drush up ctools
drush up context
drush up file_entity
drush up media
drush up rules

Best thing I’ve done to eliminate comments spam in Drupal 8

After trying a lot of different anti-spam modules with Drupal 8, the best thing I’ve ever done to reduce comment spam is to go to the Drupal admin /admin/structure/types/manage/blog/fields URI, click Edit on the Comments field, and then select the “Anonymous posters may not enter their contact information.” Since I chose that option two days ago I’ve only had one spammy comment show up in my approval list. That field gave spammers a simple way to enter a URL, and without it, the spam seems to have dried up.

The mathematical foundations of functional programming provide the strongest basis to modularize our domain models

“Streaming platforms such as Spark or Flink use functional programming principles, with Scala as the implementation language. This isn’t without a reason; finally we’ve found that the mathematical foundations of functional programming provide the strongest basis to modularize our domain models.”

~ Functional and Reactive Domain Modeling

An initial review of Functional and Reactive Domain Modeling

I’m not yet sure if I like the book Functional and Reactive Domain Modeling, but one thing is for sure: I couldn’t begin to understand it if I didn’t first do the research to write Learning Functional Programming in Scala. The author immediately jumps into monads as if they are commonly understood, and also designs his functions as “modules” in a very Haskell-ish way. I’m not saying the book is bad, just that it has a high barrier to entry.

Notes on how to update a Drupal 8 website with Drush and Composer

The process of updating a Drupal 8 website changed dramatically back in March-April, 2018, so I deleted the older content on this page and replaced it with the content below.

As of April, 2018 you now need to use Composer along with Drush to update your website. Here are my very brief notes on how to do this:

How to configure Share Buttons by AddToAny with Drupal 8

As a quick “note to self,” to get the Share Buttons module by AddToAny working in Drupal 8, I followed these steps:

- install the AddToAny module
- configure permissions so i could work with it
    - admin/people/permissions
- configure AddToAny as desired
    - admin/config/services/addtoany
- create a block, add it to a region (such as Content)
    - i actually created a block, then modified
      my theme to show AddToAny between the Contents and
      the Comments

The key to getting AddToAny was knowing to go to admin/structure/block and then selecting “Place Block” to create an AddToAny block. Not knowing that I had to do that slowed me down for quite a while.