February 2, 2021
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
January 25, 2021
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
January 21, 2021
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
January 20, 2021
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
January 20, 2021
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.
Continue reading Template suggestion for field templates per entity type - Drupal 8 & 9
August 4, 2020
By default you get the following page template suggestions for a Commerce product:
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
June 1, 2020
I previously wrote about how to create a View of content from a Group that a user is a member of. For another site, I have to show a list of other members in the same group on user profiles. Another common use case might be showing a logged-in user a list of other members in his/her group(s).
You can do this two ways:
Create a View of Group Content of type [Group name]: Group membership
Continue reading Create a View of other members of a Group - Drupal 8
May 19, 2020
Drupal has gotten so much more powerful and easy to work with, but there are still a few things that are missing that seem like they should be a given. Such as, the ability to format certain Views exposed filters, like node titles or Group names, as dropdown select lists rather than an empty textfield that requires the user to know what the possible options might be instead of presenting them.…
Continue reading Group names as Views exposed filter select list - Drupal 8
January 14, 2020
The Group module is a powerful one I turn to often when a site has a requirement for groups of users who should have specific permissions, access to edit or view specific content, etc.
A common requirement is to show a list of content belonging to the Group(s) a user is member of, using Views. That isn't as straightforward as it seems. I recently had to do this and struggled a bit, so thought…
Continue reading Create a View of content from Groups a user is member of - Drupal 8
October 3, 2019
I'm working on a website which has a list of products, displayed in a View. Each product has an "provider" who produces it, associated with the product content type by an entity reference field to a Provider content type and displayed in the view. The client wanted contact information for the providers to show up in the list as well.
It would have been a bit bulky and repetitive to have the…
Continue reading Show complementary information in a View based on exposed filter choice - Drupal 8