Blog Archives

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

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

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.

Tagged with: , ,
Posted in Development

Quick and Dirty Debugging of Drupal 8 Migrations

Introduction 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,

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

Tagged with: ,
Posted in Development

Friendly URL for Views Contextual Filter on a Boolean Field

I have a story content type that has a corresponding Views listing page. The stories can be flagged as Featured through a checkbox/boolean field ( field_story_featured ). The stories also have a Story Type value ( field_story_type ). The views listing page needs to have the

Tagged with: , ,
Posted in Development

Adding an Inline Style Attribute to an Entity in Drupal 7

The point of this post is to illustrate adding inline styles without creating template files. Normally we add classes via $vars['classes_array']  but sometimes inline styles are required. This code isn’t too useful as written (make all text red for all

Tagged with:
Posted in Development

Entity Reference Referrer – Getting Entity Reference’s Parent/Referrer Entity ID and Type

Out-of-the-box, the Entity Reference module doesn’t provide a way to access the referrer entity’s fields from within the referenced entity. I have two ways of doing this. The first is to patch the entityreference module (not ideal unless this patch

Tagged with: , ,
Posted in Development

Triggers in iTerm – Watching For Specific Strings

I was recently performing a git-add in patch mode (  git add -p ) as I normally do, and realized there were a few lines I needed to make sure I didn’t commit. These lines were sandwiched between other lines that I did want

Tagged with: , , , , ,
Posted in Development, Tech Tips