By james, 4 December, 2023
Advent Calendar door 4 containing the advent calendar module

Welcome to day four of the Drupal Advent Calendar, and today we are getting a little introspective as James Shields (lostcarpark) talks about his new Advent Calendar module and reflects on how the Drupal Advent Calendar started.

The Drupal Advent Calendar was a daft idea I started last year (2022). It literally hit me as I was falling asleep on the last night of November.

There was a little bit of a LEGO influence, as a couple of LEGO fans I know were publishing an alternative LEGO Advent Calendar. They published a parts list ahead of the beginning of December so people could collect the parts, then they were publishing build instructions each day to make up a scene during the month.

So I thought, there ought to be a Drupal Advent Calendar. I thought of clever ways we might be able to do something, but realistically none of them would be possible as the first day of December was almost upon us.

Another inspiration was the “Module of the Week” slot on the Talking Drupal podcast, which I really enjoy, and have learned of some great modules from. So I thought featuring a module behind each door would be something I could do with no preparation. Of course I’d need a bit of a write up of the modules, and maybe a few screenshots. I’ve also been contributing to the Project Browser initiative, which has been trying to design logos for popular Drupal projects, so was able to draw on some of the logos that have been created for images behind the doors.

I was up early the next morning, and wrote the first entry before work and on my lunch break, and threw together some rudimentary graphics. My partner, Fionna gave it a once over and found a ridiculous number of typos, but I got it posted.

Matthieu Scarset saw it, and suggested using his Calendar View module to display it, and it did a great job, though it did bug me a little that it didn’t look quite like a traditional Advent calendar. And, indeed, that ended up being the module on day 2.

I have to admit that I didn’t think through the plan properly, or consider how much time a new door every day would take, and it was quite a struggle to get one out every day, and a few of them slipped quite late in the day.

It was a fun project, but I knew that I’d need to plan better for this year. And I really didn’t want to do it all myself this time.

So around DrupalCon Lille, I started asking people if they’d like to take part, and I got a great response. I continued asking people to join in since then, and have been building up a team of people. The plan is similar to last year, but to have each door’s entry written by a different person. Some of them are modules, but some are more general Drupal concepts. You’ll have to wait and see as the month progresses.

Which brings us to the actual subject of today’s entry, the Advent Calendar module.

The Calendar View module always felt like a stop-gap measure. What I really wanted was a module that displayed the calendar doors, and let you click to open them, keeping each door’s entry secret until you clicked to open it (and, of course, not letting you open a door until the appropriate day).

2023 Advent Calendar
This year’s Advent Calendar displayed by the module

The calendar itself uses a View style plugin that displays the doors in a neat grid.

As it uses a view, it’s up to the site maintainer to arrange their content type and view to select the needed fields.

The actual doors are displayed using a Single Directory Component (SDC), a new feature of Drupal 10.1. The component takes a number of properties like the door number and the image inside the door. The SDC provides open and closed door images. Currently these are fixed, though I would like to make them configurable.

The SDC made it easy to attach CSS and Javascript, and keep everything neatly wrapped up.

The bit that’s currently a bit ugly is the connection between the View and the SDC, and uses a template. I hope there will be continued enhancement of the SDC capabilities in future Drupal releases. Being able to embed a SDC directly in a View and connect fields to its properties would be a game changer.

Screenshot of view settings
Setting up the view

I want the module I wrote to be available to other sites. Being able to drop an Advent Calendar into a Drupal site would be a nice feature. However, currently it’s a bit fiddly.

So, to make things easier, Advent Calendar has a sub-module called “Advent Calendar Quickstart”. This sets up everything you need for an Advent Calendar, including a content type, and a view, and creates 24 nodes to populate it. Once the calendar has been created, the Quickstart module can safely be uninstalled. And it creates a taxonomy term for the current year and links the items to it, so the next year you can install it again to get another calendar for that year.

I haven’t managed to get all the features I want in it yet so hopefully the Advent calendar will look nicer as I finish bits off during the month.

It’s very much a beta version at present, so feel free to play with it, but don’t be surprised if there are still a few bugs.

I hope you are enjoying this year’s calendar so far, and also that we can do something even bigger for next year.

Photo of James ShieldsJames Shields is a software developer working in the financial services sector, and a Drupal hobbyist. In his spare time he enjoys building giant LEGO models, organising science fiction conventions, and going on hikes with his partner and their dog.

Comments

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.