Theme colour switcher

Blog

I really appreciate when a website or app offers the choice of dark mode. It makes reading at night much easier on the eyes, and some people prefer it at all times due to vision issues. I'd never implemented a dark mode switch, so one of my goals for my blog redesign was to do so, both for reader convenience and to gain the experience. Here's how I did it. It might seem surprising that I discuss…

Continue reading How I created a dark mode switch for my Drupal 9 site

Several years ago when I was working at Romni Wools, a yarn shop in downtown Toronto, I was asked to make a sample from the then-new Malabrigo Twist yarn. I found this pretty Shetland Eyelet lace pattern in Barbara Walker's A Treasury of Knitting Patterns (page 179), which worked up nicely into a hat. This hat requires 100 grams of aran weight yarn (the sample used 55 grams/83 yards, so even if…

Continue reading Chelsea Hotel Hat Knitting Pattern

I guess I'm a little obsessed with the Group module, or maybe it's just that I've been using it a lot lately, and still learning its ins and outs. One of the main purposes of Group is to control user access to various content types, based on what Group(s) the viewing user and content are in. Each Group type has an extensive permissions table where you can control permissions for anonymous users,…

Continue reading How to control access to content using the Group module - Drupal 8 & 9

Previously, I posted about how to create a view on a user's profile of content authored by that user, limited to content in Group(s) the viewing user is a member of. That tutorial shows how to accomplish that with a view of content (Drupal nodes) which are in Groups. The person who requested that tutorial later told me they needed a view of Group content. Group content is the relationship between…

Continue reading Show group content on author's user profile, limited by viewing user's Group membership - Drupal 8 & 9

The following preprocess function will give you unique classes on the body tag for each Group content type (from the Group module). It adds two classes, one that includes the Group type that the content is in as well as the Group content type (e.g. group-content--client-group--node-page); and one with just the Group content type (e.g. group-content--node-page). Place this code in your theme's .…

Continue reading Add body classes per group content type - Drupal 8 & 9

The following template suggestion (placed in your theme's .theme file) will give you field template suggestions per entity type, e.g. field--node.html.twig, field--group.html.twig, field--media.html.twig, etc. I wanted to theme all fields in Groups the same way, and didn't want to have to create field templates for each group type, which was the least granular template suggestion available. This…

Continue reading Template suggestion for field templates per entity type - Drupal 8 & 9

See also how to do this with a view of Group content Someone contacted me asking for help with the following: I am trying to look at the particular user profile, and below that profile contains a stream of content nodes which I will be able to see only content created by that particular user in group that I am a member of. Example. If A is a user who created 2 Group’s and has added me to one of…

Continue reading Show content on author's user profile, limited by viewing user's Group membership - Drupal 8 & 9

I wanted to change the format of the comment submitted timestamp on my blog, and figured it could be done in Twig - but nope. There's an active issue on Drupal.org to allow the format to be changed in the UI, but until that's done, you need to use a theme preprocess function. function THEMENAME_preprocess_comment(&$variables) {  $date_formatter = \Drupal::service('date.formatter…

Continue reading Change format of comment created date - Drupal 8 & 9

This is slightly adapted from presentation notes, so it's a bit sketchy. It's more of an outline of requirements, rather than code samples. I may add those later. Also, note that I've only covered two scenarios: a dropdown menu, and a menu that covers the entire screen when opened (modal dialog). There may be different considerations for other styles. Mobile menu: usually the site's main menu,…

Continue reading How to create an accessible mobile menu

By default you get the following page template suggestions for a Commerce product: page--product--[ID].html.twig page--product--%.html.twig page--product.html.twig page.html.twig Here's a template suggestion for custom page templates per product type: /**  * Add page templates for Commerce product types  * Example: page--product--event.html.twig  *//** * Implements…

Continue reading Drupal 8 theme suggestion for Commerce product page template per product type