↓ Skip to main content

Creating a Membership List in Drupal 11 with Aggregating Views

·4 mins

I’ve written before about our use of Drupal for the Southampton Orienteering Club website. We’re now on Drupal 11, and my opinions haven’t really changed. Upgrades are still painful, particularly the community modules that we have to leave behind each time. The user experience for creating content also lags behind newer alternatives. We have a significant amount of historical content on the site (not all of it publicly visible), making a move a daunting proposition. In the meantime, as this post demonstrates, we continue to utilise the powerful features that Drupal and its ecosystem offer.

We had a requirement to provide a membership list for use by the club’s members, which would provide names, approximate home location (to facilitate lift sharing), and a contact mechanism. Previously, it fell to the membership secretary to create this list manually; however, given that nearly all members have an account on the website, it felt like there was a better way.

We already had a permission role that was granted to club members (allowing them access to the members’ area), so it was trivial to create a page that listed all of the website users in that role (and limit access to the list to those in that role). Drupal lets you add custom fields to the user profile. We already have fields for forename and surname, to which I added a location field, which we populated from the old membership list.

User profile

Drupal also has a built-in mechanism for users to contact one another. Users can select the user they wish to contact and provide a message, which is then emailed to the recipient with the originating user as the sender. This has the benefit that users see messages where they are most likely to notice them (in their inbox rather than in some additional system), but without having to expose everyone’s email address to everyone else, which was an area of concern. Better still, users can indicate in their profile whether or not they wish to be contactable.

Contact form

So far, so good. We had a list that showed members’ names, locations, and a link to their contact form if they hadn’t disabled it. The last thing we wanted to add to the list was some additional data for each member, highlighting honorary members, any qualifications (e.g., first aider or coach), and any posts they might hold (e.g., secretary or chair).

We already had a Drupal node type to represent a post, which is then linked to multiple users. This was being used to generate the committee page. I decided to extend this to cover the other scenarios. Drupal views allow you to specify reverse relationships, so for each member, it would retrieve all of the ‘posts’ the member held. Unfortunately, it then renders this as if it were an outer join in SQL, with multiple rows in the table for a member, one for each post.

This is where the Views Aggregator Plus module came to the rescue. Once installed, I could select the “Table with aggregation options” format for my Drupal view. Getting the correct settings was then a bit finicky. I had to add a hidden field with the user’s UUID. I then configured the view to group the post holder relationship using the “Enumerate (sort, no dupl.)” function and group the UUID using “Group and compress” as shown in the following screenshot.

Table with aggregation options settings

The module is significantly more powerful than this. It will, for example, allow you to perform operations such as COUNT, MIN, and MAX on the aggregated rows. That’s maybe for another day!

One further tweak was then needed. The table was styled differently from all of the other tables on the site. Rather than try to replicate that styling, I changed the class in modules/contrib/views_aggregator/templates/views-aggregator-results-table.html.twig from table to views-table.

The final list (or at least the important section of it!) then looks something like the following:

Membership list

Related

Updating the symbol set and magentic north with OpenOrienteering Mapper

·4 mins
I spend a couple of hours a week hanging around the leisure centre at Fleming Park while Emma swims. For the past month or so, I’ve been using that time to update the orienteering map of the area, ready for the SOC Summer Series event there in August. The fairways of the old golf course are becoming increasingly overgrown, aided by the planting of lots of new trees. I therefore wanted to update the map to the latest sprint specification, ISSprOM 2019-2, so that I could make use of the ‘rough open with scattered bushes’ symbol. Although it hasn’t shifted much since 2016, I thought it was also time to update magnetic north. The following directions for OpenOrienteering Mapper (OOM) are based on those I received from the club’s mapping officer, Mark Light.

Lockdown 2

October started with Duncan’s birthday. It was a pretty quiet affair at home with Christine’s parents visiting and a film in the evening. Friday night has become film night more generally now (after a trial of Sky Cinema we signed up for a discounted subscription). Trying to select a film is always a bit of a trial, particularly balancing Emma’s desire for action against age-appropriate content for Duncan! I’m usually the one who ends up making a final decision to try and satisfy everyone’s needs.

Socially Distanced Summer

·5 mins
July continued in much the same theme as June with a mixture of online and socially-distanced face-to-face activity. The children continued to be schooled at home until the end of the summer term. Duncan even got to meet his teacher for next year (who is new to the school) online. The orienteering club continued to have online sessions on Zoom, including the AGM at which I was delighted to receive the “outstanding contribution award”! Duncan and I continued with PE with Joe until it stopped at the end of the term.