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.
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
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
I’m a big fan of the book, Functional and Reactive Domain Modeling, and these are some of my notes (“CliffsNotes”) from the book, most of them coming from the first chapter.
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.”
To create a new book in Drupal 8:
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.
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:
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.