Theme colour switcher

Blog

Please note I'm not referring here to showing a block with a list of content that shares the same taxonomy terms as the content it is displayed on, a.k.a. a "related content" block. There are reams and reams of tutorials out there showing you how to do that. This use case is when you have a specific block, maybe just some custom output, that you only want to show on content that is tagged with…

Continue reading How to show a Drupal block on content tagged with specific taxonomy terms

A common need when displaying dates on a website is to display the start and end date of an event. If your date field is a standard Drupal datetime or daterange field, that's fairly easy. (See my post on how to get values from Drupal date fields in Twig). If your date field is a Smart Date field and allows for recurrence, that's slightly more complicated, as it is now a multi-value field (…

Continue reading Get specific key values from multi-value field, e.g. first and last dates from recurring Smart Date field

    <a href="{{ file_url(node.field_document.entity.field_media_document.entity.uri.value) }}">      {{ node.field_document.entity.field_media_document.entity.filename.value }}    </a> Of course you'll need to replace the fieldnames with yours. The file_url function is necessary to transform the URL into a workable…

Continue reading How to get file URI and filename from referenced media entity field in Twig

One of my clients is a site which has extensive audio recordings. Their current site uses the default HTML5 audio player, but they want something that is more customizable to fit with their design and needs. One of their requests was to be able to set audio playback speed. One of my priorities was that the audio player be fully accessible. To display the audio player, they are using the Drupal…

Continue reading How I customized jPlayer for accessibility and added playback rate control, Drupal 9

The Drupal Responsive Background Image module is a nice little module that gives you a preprocess function to display an image field as a, you guessed it, responsive background image. This is useful for hero images, when you want the image to display at different sizes on different-size screens, because you don't want to load an enormous 2000+-pixel-wide image on mobile screens. The creator of…

Continue reading How to use Responsive Background Image in a page or node template

Just plopping this here for future reference and in case it might be useful to someone. I'm having to work with a platform which shall remain unnamed but whose code makes working with it very difficult. Among other things, it gives form elements unique classes with ID numbers, but for some reason no IDs. So I needed to filter the class list to find the unique class so I can set the element's ID…

Continue reading JavaScript function to find a class on an element containing a particular string

Today I had an interview for a job. These days I'm not really job hunting; I have enough freelance work, though it'd be nice to get more hours. A recruiter reached out through LinkedIn and I was interested enough to follow up. The interview was short, and I have been through enough of them in my working life to know by the way they wrapped it up that they wouldn't be going further. Unlike most…

Continue reading Potential vs. fixed mindset

Background: I work on a site with different groups of users, to manage which we use not only core Drupal roles and permissions, but the Group module. Recently the site owner requested to add a Workflow to a content type. Clients need to be able to see the workflow state and change it, but not be able to see or edit the original node, or even the workflow tab on the node. We manage client access…

Continue reading Allow users to update an entity's Workflow status from a Drupal view

This is a followup to my post "Print formatted date with correct timezone from datetime or daterange field in node and Views templates - Drupal 8". That post deals with core Drupal Date and Daterange fields. Recently I've been working on a site with events which use a Smart Date field. The Smart Date module offers many features that core Drupal date fields don't, such as recurrence. Raw Smart…

Continue reading Print raw values from Smart Date fields in Twig templates - Drupal 8+

A very common website pattern is a list of teasers for blog posts or articles, each with a heading, short text extract, maybe an image, and a link whose text label is something like "Read more" or "Learn more". Those "read more" links are very bad news for accessibility, mainly for blind users. Why? Blind users often hear links out of context. This may happen by tabbing through focusable elements…

Continue reading "Learn more" or "read more" links: bad news for accessibility