You are here

Drupal 8

Group names as Views exposed filter select list - Drupal 8

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.

Create a View of content from Groups a user is member of - Drupal 8

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 this solution might be useful for someone else.

Show complementary information in a View based on exposed filter choice - Drupal 8

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.

Calculate a value from options field in Webform custom composite element with Twig - Drupal 8

Recently, I was creating an event registration Webform. I created a custom composite field with the fields needed for each registrant: first name, last name, and a set of three radio options for their organization status: member, non-member, membership fee included in event registration. Each status has a different registration fee.

I then wanted to create a computed Twig field that would calculate the total registration fee by getting the data from the chosen radio option for each attendee and adding it up. This proved surprisingly tricky.

How to create a View with a featured item and a list that excludes the featured item, Drupal 8

A common pattern for websites is a list of content, for example news, with one (or more) featured items, followed by a list of a few more items, excluding the featured one(s). This seems like it should be simple to do, but it's not as straightforward as it seems.

Print formatted date with correct timezone from datetime or daterange field in node and Views templates - Drupal 8

I've been working on a site with events, and tearing my hair out over how to print formatted dates with the correct timezone value in Twig templates, specifically node.html.twig and views-view-fields.html.twig.

Add visually hidden file type indicator to file field links - Drupal 8

I'm working on a website which has icons on file upload links, like so:

PDF file links with icons

This is nice for people who can see the icons, but what about those who can't? Accessibility means giving all users an equivalent experience, regardless of how they're accessing the site.

If the icons were inline images, we could put an alt of "PDF" on them and be done. However, in this case, they're background images.

How to make search block form label visible - Drupal 8

By default, the label for the core Search module text input in Drupal 8 is set to invisible, that is, it's present but hidden by applying the "visually-hidden" class so users of assistive technology can read it. But what if you want to display it visually?

That's not so easy. There's no way to do it through configuration, and little to no information about how to do it with code.

I muddled around and finally found where the visibility was being set, in SearchBlockForm.php in the core Search module. In there we find:

Pages