David Lohmeyer's Blog

Nesting module-defined menu links in Drupal 8

When you provide a module-defined menu link in Drupal 8, there is some great documentation on how to add a menu link on Drupal.org. This gets into how to provide a menu link with YAML. In a lot of cases, you might want to nest this menu link under another item. This is especially the case if you were providing a menu link for something in the main menu of your site.

Dragon Ball Super CCG Google Sheets Card List

I've been playing the new Dragon Ball Super CCG. It's great! it has a lot of strategy like Magic: The Gathering and seems to be a promising new card game. I noticed the official site's card list was not very printable for collecting purposes, so I put together this Google Sheet of the Galactic Battle card list and other current cards (check the tabs).

Clean up database pollution from the migrate Drupal module

I'm working on a large, complex migration from Drupal 7 to Drupal 8 right now. One thing I noticed is that the migrate modules pollute the database with an unreal number of tables which allow migrations to be re-run, etc. Well if you don't need that, here's how to remove these tables. Currently the migrate modules don't clean up after themselves. Put this in a custom module or PHP script that has bootstrapped Drupal. Note this code only works in Drupal 8. Shown is a .install file for a custom module. If you uninstall the custom module, it will run the cleanup:

A new place to buy Gunpla, or Gundam Plastic Models

Back when I started web design, one of my first sites was related to Gundam, the popular anime from Japan that has been around since 1979. The site, called Gundam Plus, was quite popular. I ran this site for 7 years during my youth and learned a ton about Gundam and technology, and eventually it helped propel my career towards web development.

Quick tool for generating Drupal hash salt strings

Every time I install Drupal I find myself fumbling for a nice hash salt string. Instead of finding a random solution, I decided to put together a quick page that generates a random hash salt string and get a shiny domain for it.

Check out DrupalHashSalt.com (easy to remember!) next time you need a random hash salt. I also posted the code used to generate the string.

If you have ideas for this site feel free to contact me.

Reverse core threaded comment ordering in Drupal 8!

The default ordering of all comments in Drupal 8's core comment module is ascending, meaning the oldest comments are displayed first. Sometimes you don't want this.

Assuming your comment field's machine name is field_comments, put this code into a module to get descending comments. I was having trouble with threaded comments, but this works since it alters the query by the c.thread database column instead of just 'torder':

Telling Ubuntu 16 to use a different PHP version on cli

When you have multiple versions of PHP installed things can get a bit wonky. PHP 7.1 has broken a lot, and I've noticed most LAMP apps and a lot of commandline tools such as Drush just aren't compatible yet.

With Nginx, it makes it easy to run your sites on a specific PHP version like 7.0, but if you install 7.1 on your server you might want cli applications to use 7.0 still.

Remove the comment text area filter tips link in Drupal 8

Sometimes you just want a cleaner comment entry box. Here's a quick Gist module that will remove your comment tip link beneath comment form body entries in Drupal 8. This uses a form alter to remove the filter help on the comment form.

If you wanted an even cleaner look, you could remove the other text below the comment box altogether by overriding filter-guidelines.html.twig and filter-tips.html.twig in your theme!

Scaling block output as Twig variables in Drupal 8

With Drupal 8's Object Oriented focus, it's just a matter of time before cooler approaches to the theme's giant template.php (now yourtheme.theme) file are found. I've written a nicer way to get block output into the $variables array in page and node preprocess functions. What this allows you to do is use simple variables like {{ my_cool_block_stuff }} in yor Drupal Twig templates.

Adding the node class to a body HTML tag in Drupal 8

Doing some hacking at DrupalCon New Orleans and my use case is to add a node-* class to the body HTML element in Drupal 8. With the preprocess hook in D8 it looks like there is access to different variables than previously. To get the node id one has to look at the cache tags. Here's how I did it:

In mytheme.theme: