User-chosen Field Output Styles in 5 minutes using Display Suite

I’m working on a site that has a “Statistics” paragraph bundle. The output looks like this:

The specification calls for the content author to be able to choose between a few different visual styles for the header (title), shown as Statistics: 3 Up Feature Ipsum Sit H2 in the screenshot above.

The simplest way to achieve this is to add a field to the paragraph bundle:

Note that the key (key|value) needs to work as a css class.

After creating the field, add it to the Manage form display where desired:

The last step is to add a class, based on the chosen value, to the Section Header field when the paragraph item gets rendered. If you’re using Display Suite with field templates enabled, this is a very simple change! You don’t have to write any code, in fact. Simply edit the output of the Section Header field by clicking the cogwheel:

Next, browse for the appropriate placeholder (click Browse available tokens):

In my case I browsed for Paragraphs > Header Style > Text value. The token is: [paragraph:field_header_style:value]

Finally, just append that token to the end of the Classes field (shown above). I chose to prepend “header-style” to the beginning for a final value of header-style–[paragraph:field_header_style:value].

That’s it! Test it out by adding a record and setting the header style:

View the item on the frontend and you should find the additional class:


Tagged with:
Posted in Development

Adding Fields to Inline Entity Form Table

Inline Entity Form is a useful module for reference entities and being able to edit them in place.

Here’s what the edit form looks like out of the box for an unlimited value entity reference:

Default output

Often it’s helpful to provide additional information to your editors.

If you have a look at inline_entity_form.module you will find a function called theme_inline_entity_form_entity_table(). Within this you will see how this table is built, and how you can manipulate the form to add additional columns of information. Read more ›

Tagged with: , ,
Posted in Development

Using the Messenger Service Instead of drupal_set_message in Drupal 8

As you may know, drupal_set_message()  is deprecated in Drupal 8.5.0.

Here’s a quick example of using dependency injection to use the new Messenger service:



Tagged with: ,
Posted in Development

Automatically Put Files Into a YYYY/MM Directory Structure


Tagged with:
Posted in Development, Tech Tips

Using PHPStorm for Git Diff and Merge tools (Mac)

You love git-difftool, right? Of course! You also love PHP Storm, right? Of course! This easy procedure lets you use PHP Storm as your git-difftool.

  1. Open a project in PHP Storm
  2. Click Tools » Create Command-line Launcher…
  3. Edit your ~/.gitconfig file:
  4. Open the project in PHP Storm (see notes below)
  5. Open iTerm2 (or any other terminal emulator)
  6. Use git difftool as you normally would (e.g., git difftool .htaccess)


  1. If you don’t have PHPStorm open when you try to use git difftool it doesn’t seem to work. I need to see if I can get it to open non PHP Storm projects, and/or I need to figure out how to switch on-the-fly between vimdiff and PHP Storm as my difftool.
  2. If you have PHP Storm open but the project itself isn’t open, “Annotate” is not available on right-click. Other functionality may be missing too. If you project is already open in PHP Storm you can annotate the diff!

Thank you to JohnAlbin for the configuration snippet above.

Tagged with: , ,
Posted in Development, Tech Tips

Find and Open (in vim) Multiple Files

This is a quick set of examples for finding and opening multiple files in Vim.


Tagged with: ,
Posted in Development, Tech Tips

Basic HTTP Authentication in Drupal Site Using settings.php

Here’s a quick and painless way of preventing public access to a Drupal site using settings.php (or settings.local.php):


Tagged with: , , ,
Posted in Development

Valet+ Quickstart for Drupal Development

Here’s a file that I’ve developed over time. It explains how I setup and use Valet+ for quick and powerful Drupal development.

Sorry for the formatting. I’ll get markdown support on my blog sometime…


Tagged with: , , ,
Posted in Development

Setting up OCI8 (PHP Oracle module) on Webfaction

Webfaction, my favorite web host, allows you to compile PHP modules in your home directory for use on your websites. Here’s the process for configuring OCI8 to talk to Oracle databases:


Tagged with: ,
Posted in Development

Mac High CPU Usage – WindowServer

DISCLAIMER: I’m writing about my personal experience here. I am by no means doing some exhaustive investigation. The changes I explain below seem to make a difference, at least according to what Activity Monitor is showing for CPU usage.

My laptop (3.1GHz i7 MacBook Pro with 16GB of RAM) has enough of power, so why has it been such a dog since starting from scratch with a fresh OS? A colleague posted an animated Gif today in Slack and my MacBook fans kicked in and it sounded like it was getting ready to fly away. This was the last straw in what has been weeks of wondering why my laptop has been slow.

I opened Activity Monitor and found that my WindowServer process was using a significant amount of CPU resources (up to 77% when the animated gif was visible on my screen), and that it has used significantly more than the next heaviest process since I last rebooted.

I understand that it’s probably a pretty heavy process, but it got me thinking, and Googling. As it turns out, when something is being drawn to the screen it takes processing power; go figure! One of the top suggestions was removing or disabling things from the menu bar that are constantly updating. The suggestions included CrashPlan and Little Snitch Network Monitor. Wow. I use the latter! I opened the Little Snitch preferences and unchecked “Show network activity in menu bar” and voila! the WindowServer process memory dropped about 15%. Then I closed the animated gif my colleague posted in Slack (the only other thing on the screen that was moving) and voila! it dropped again.

Now, as I’m looking at my CPU Time in Activity Monitor I’m thinking through what I really need running. Is the “Next Meeting” (which shows the name and time of my next meeting in the menu bar) application really worth running 24/7? I don’t think so; especially if I have more important things for my CPU to be doing. After quitting this application my WindowServer CPU usage dropped to 6.6%.

I’m going to continue to trim the fat to see how lean I can make my machine. Obviously it doesn’t stop at just trimming out running applications, but I’m blown away by the impact of small changes like these.

Tagged with: ,
Posted in Tech Tips