Blog Archives

Using GROUP_CONCAT to Combine Rows in a Drupal Query

Recently I was working on a D7 to D8 migration. I was trying to import news items and their taxonomy terms (among many other things). To make things simple I wanted the query results to have (for each node) a

Tagged with: , , , , , , ,
Posted in Development

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:

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: mymodule.services.yml

src/MymoduleAuthentication.php

 

Tagged with: ,
Posted in Development

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). I’ve been using this for development and staging sites that I want to keep private. If you want this to be available

Tagged with: , , ,
Posted in Development

Drupal 8 User Photo Update Form

Recently I had to come up with a simple way for users to change their member profile photo without requiring them to visit the user edit screen. Here’s the result: First, I added a new Image field called “Member Photo” to

Tagged with: ,
Posted in Development

Creating a Drupal 8 Route to a User Page with Dynamic User Object

It took me some time to figure out the right combination of properties to make this work. My goal was to create a form that lives at /user/UID/photo (think /user/1/edit). I wanted the user object to be passed into the

Tagged with: ,
Posted in Development

Make a Field Label “visually-hidden” in Drupal 8

Using the Form API you can add a visually-hidden class to a field using the “#title_display” property as shown here:

 

Tagged with: ,
Posted in Development

Drupal 8 Search API Tips

Here are some quick tips for configuring Search API for Drupal 8. Easy Indexing If you’re like me you rely heavily on Display Modes (aka View Modes) for your entity types. The most convenient way to get Search API to index

Tagged with: , , ,
Posted in Development

Manually Checking Path-based Visibility in Drupal 8

This mimics the path visibility settings on block configurations.

 

Tagged with: ,
Posted in Development

Block Caching “Gotcha” in Drupal 8

I recently had a fight with the Block system in Drupal 8. To be brief, if you’re trying to disable caching on a block, make sure to set the #cache element regardless of whether the block has output or not.

Tagged with: , ,
Posted in Development