Drupal 8.4x: Add Timezone to Date or DateRange Field

Here's the controlling issue for adding timezone support to Drupal core. As of now, August 1st, 2017, it doesn't appear to be ready.

Instead, I just added a timezone field to the node using the Timezone module, then appended it to the date range on field preprocess.

This won't work for you if you have multiple dates on an entity with different timezones (you might want to try the patch linked above), but it will fit most use cases.

Drupal 8: Get URI, Title, and Alt from Media Entity Reference Item

Over the last several days, I've railed in my head against the matroshka structure of Drupal entities. But when I tried to break out some helper functions, and when I realized what each of the different properties each entity had, I realized the complexities of entities were warranted. Life is complex, and thus Drupal is complex.

Entity references load a Media Entity, which load an Image from an image field, which load a File. The alt and title are on the Image, while the file URI is on the file.

Get File URI from Media Entity Reference Item in Drupal 8 OR Wrong File Loaded

Another day learning Drupal 8, but today is troubling.

Here's where I'm at. I'm theming search results, and I need to load field values to pass to twig templates—specifically a styled url for img src.

Entities values are not loaded on search results, only little snippets, so I have to load them the hard way, because we want images and nice theming on our search results.

Config Management Roundup

Quite the problem—Drupal config management on local and prod.

Drupal 8 can be punctilious: it will simply refuse to work if there's a mismatch between database and config objects on the filesystem.

So... how do we manage two sets of configurations—one for local, and one for production?

The Problem

I have modules like varnish installed on production that shouldn't be enabled on local, and modules that are enabled on local that shouldn't be enabled on production.

Install PHPUnit for PHP 5.6 and PHP 7.1 on Homebrew

So you found this post because you just updated or installed PHPUnit, you're running PHP 5.6, and you get this error:

"This version of PHPUnit is supported on PHP 7.0 and PHP 7.1.
You are using PHP 5.6.30 (/usr/local/Cellar/php56/5.6.30_6/bin/php)."

Maybe, like me, you're cranky about virtualization and you're using a PHP switcher to switch between PHP 5.6 and 7.1.

The solution?
brew install [email protected]

Responsive iframe in Drupal 8 from Client Embed Code

Nobody likes iframes. That's because you can't style their innards, and they aren't responsive... or are they?!?!

The first thing to know about here is the padding height hack. This allows you to set the height of an object relative to the width, because while height is always as a percentage of the container, padding height is as a percentage of width. So all you have to know is the ratio of height to width and you can make a thing that responsively scales.

.gitignore by branch

Have you ever wanted to .gitignore a file by branch?

The classic example for me here is versioning the generated styles.css file on master (which is deployed to production) but not on develop (which is used for pull requests).

Versioning the styles.css file can result in merge conflicts or PRs that are just messy.

Here's the script I wrote.

Read the comments for installation notes.