Alter Date Format in a Drupal 8 Migration

Per you can now use the format_date plugin to alter date formats like this:

I do always recommend using skip_on_empty before any other process plugins.

Tagged with: , ,
Posted in Development

Link to a View (with Contextual Filter value) If It Will Have Results (Drupal 8)

Returns a link render array.

Tagged with:
Posted in Development

Drupal Views – Show One (Most Recent) Item Per Group

Alright, the title is a bit misleading because I’m not using Groups, but it is the best explanation of what I’m achieving with this example. My goal is to show a list of the most recent blog post in each category, where clicking the category takes you to the associated post.

I have a content type called Blog Post which has the following fields:

  • Date (field_blog_date – date field – single value)
  • Category (field_blog_tr_category – taxonomy reference field – single value)
  • Items (field_blog_cr_items – content reference field – unlimited values)

Read more ›

Tagged with: , , ,
Posted in Development

Automatic Redirect by Path in Drupal 8

This example shows how to intercept a Drupal page request, determine if the desired path matches the one we wish to redirect, find the “latest” node of a particular content type, and redirect to that node instead of the original page.

I have a page on my site called Updates. This landing page exists only so that there is a menu item and proper breadcrumb trail; users never get to this landing page. Rather, they’re redirected to the latest update when they attempt to visit the landing page. Updates are nodes of the type update. Each update node (when viewed as a page) shows a Recent Updates block in the sidebar with links to of all of the most recent updates.

The landing page is a Views-based page (so it doesn’t get accidentally deleted). There is also an All Views-based page that lists links to all updates. If the system cannot find the latest update the user will be redirected to the All page. Read more ›

Tagged with: ,
Posted in Development

Drupal 8 – Formatting a Date Field in Twig

Here are the four easiest ways I’ve found to show dates via Twig inside of a node template.

They all result in the same output.

Use the field’s formatter settings; include wrappers

This is the only example that includes wrappers. The rest output just the date.


Use the field’s formatter settings

This will use the format defined in Content type » Manage Displays » Your View Mode.


Use Twig date filter + a defined Drupal date format

I have defined, via the Drupal UI, a date format. Here’s the config for it:

uuid: 1a50c79f-96df-45de-9a21-32e0d8327806
langcode: en
status: true
dependencies: { }
id: short_mdyyyy
label: 'Short - m/d/yyyy'
locked: false
pattern: n/j/Y


Use Twig date filter

Tagged with: , ,
Posted in Development

Quick and Dirty Debugging of Drupal 8 Migrations


If you’re working on a migration in Drupal 8 and you’re finding yourself a little confused by the YAML-based configuration, I strongly recommend using a proper debugger so you can step through the code. You cannot step through the YAML, but you can step through the code that the YAML triggers. This blog post is my attempt to share a few tips/tricks I’ve learned along the way. This isn’t meant to be an exhaustive step-by-step debugging tutorial, so you may have to do some Googling to fill in the blanks.

Disclaimer: Some of the information is PHPStorm-specific, but you should be able to adapt to whichever debugging tools you use. Read more ›

Tagged with: , ,
Posted in Development

Database Refreshing Pattern in Drupal 8 – Testing Config Changes

I’ve been working on some Drupal 8 migration work. Given that most of the work I’m doing takes place in “config” I have to keep refreshing/reinstalling the config on my site. For a long time I would use Configuration Installer to pull in the changes I’ve made before repeatedly testing the migrations. The pattern is: Develop, overwrite config, test, develop, overwrite config, test.

Read more ›

Tagged with: ,
Posted in Development

Lathe Stand Plans

Here’s my 5-foot adaptation of the lathe stand from (Thanks Keith!)

Here’s what it took for supplies:

  1. (1) 4×8  3/4 birch plywood
  2. (7) 2×6-8ft
  3. (3) 50lb bags of sand (had to fill trash 4 trash bags because 50lb bags too big)
  4. (1) 4×8 hardboard
  5. Lots of Kreg pocket hole screws
  6. Wood glue
  7. Countersink bits

My legs are at 5 degrees. The only adaptation I made as I built it was that I needed more room for my feet, so I moved the entire “sand box” up several inches. The only thing this changed was to shorten the length of the two 2×6 cross boards at the bottom (the one that says 9 7/8″ in the drawing).

Tagged with: , , ,
Posted in DIY, Woodworking

Bookmark with Dynamic Components via Keyboard Maestro (with Toggl Reports example)

Here’s an example of how you can use Keyboard Maestro to create bookmarks that use dynamic components. For this example I wanted to create a bookmark that would give me the correct URL to get a report of the last 365 days of Toggl time entries. Toggl lets you pass a start date and an end date in the URL. Using KM it’s easy to replace those values with calculated date values.

Click the screenshot at the right to see the macro, which I’ve also provided here: Toggl entries for the last 365 days.kmmacros. Read more ›

Tagged with: , , , ,
Posted in Tech Tips

Adding Entity Wrapper Class from Field Value using Display Suite

NOTICE: This works fine in Drupal 7. For Drupal 8 please see

Sometimes as a developer you need to provide your Drupal authors with the ability to choose different variations of a particular content object. For example, imagine you have a Callout paragraph bundle and you want the author to choose between a Dark or a Light colorscheme; if the user chooses Light, the font colors appear dark over a light background. To achieve this you need a dark or light class on the entity wrapper based on whichever the author chose; this would let you write CSS to target each color scheme. Using Display Suite this is an easy problem to solve and doesn’t require any preprocess code or other hand-coded solution.

This solution requires Token and Display Suite. You will need to enable the ui modules from these, as well as ds_extras to give you the CSS class functionality. Read more ›

Tagged with: , , , ,
Posted in Tech Tips