Blog

RSS feed

Adding GitLab CI to one of my contrib modules

I had a few hours free at the end of January to get GitLab CI enabled for the daterange_compact module.

When I first wrote this module, Drupal projects could opt-in to automated PHPUnit testing. This module has always had plenty of test coverage, so having tests run for every patch was so useful. Somewhere along the line something changed and the automated tests stopped running (though the tests themselves still were still fine). Nowadays, projects can have their own GitLab CI pipeline, but I’d never got around to setting that up.

The first task to fail was cspell, a spell checker for comments. I had no idea such a thing existed, but I soon found out.

Drupal Core uses US English spelling for all source code, including comments and names.

🤷 Whatever:

- * behaviour of that field formatter, and the default configuration.
+ * behavior of that field formatter, and the default configuration.

Pick your battles.

Next was the PHP code sniffer. It checks coding standards, comments, whitespace etc. I tidied up a few things here, adding some missing functions comments and fixing whitespace issues.

Sometimes, it’s ok to be a bit lazypragmatic:

// phpcs:ignore
private static function isSameDay($start_timestamp, $end_timestamp, $timezone): bool

The last error was more interesting. An actual test failure!

What?! These tests have been working for years, and I’ve always been dilligent to run them locally whenever I work on this project. Moreover, they still passed locally. But one of them failed on GitLab CI.

The offender was a test that makes sure we revert to a fallback date format when something isn’t available. And that fallback date format has changed in Drupal 11.1. I was still running 11.0.

So the test needed updating to match. It now expects different results depending on what version of Drupal is in use.

$expected = \Drupal::VERSION >= '11.1'
  ? 'Thu, 1 Jan 1970 - 10:00 - Thu, 1 Jan 1970 - 11:00'
  : 'Thu, 01/01/1970 - 10:00 - Thu, 01/01/1970 - 11:00';

It was good to get the CI pipeline working. As a bonus, I got to write a line of code too!

Read more

August Drupal contributions round-up

A new release of the compact date/time range formatter module, with support for optional end dates. We now support core’s datetime & timestamp fields now, not just ranges, which makes sense if you want to render “3:00pm” as “3pm”.

Dived down a rabbit hole about regions being rendered even when they are empty. This affects LocalGov Drupal too. I don’t think this is something that can be “fixed”, per-se. It’s more a case of choosing between performance and design accuracy. I’ve started a sandbox module to expose that choice.

Read more

On giving Drupal development advice

In my Drupal development and consultancy work, I often advise development teams on how best to implement something in Drupal. I was asked recently how I—perhaps as the sole Drupal specialist in the room—validate the advice I give. I hadn’t really articulated that before, so I wrote down some thoughts.

Read more

ffconf 2017

Web components meet 8-bit video games

I recently attended ffconf - a conference in Brighton for web developers. This is the first time I’ve been. The event is broad and covers general topics about the web as a whole, rather than covering the latest trends in web development. That’s what drew me to it in the first place; as someone who has been primarily involved in “backend” development but wants to diversify a bit, I wanted something that I was sure would be a worthwhile investment, rather than a gamble on a framework I may never use.

Read more

The map is not the territory

I recently attended an excellent workshop on OpenStreetMap. Entitled The map is not the territory, we looked at maps beyond being something that's purely visual, and delved into the data behind them.

It turns out there's far more detail there than first meets the eye.

Read more

When your composer build breaks

Yesterday a project on github was moved, causing Drupal's own build process, and that of many other websites, to “break”. Here's what happened:

  1. The coder library was removed from github (it's main home is on drupal.org).
  2. Drupal core's composer.json had a reference to the now non-existent repository.
  3. Anyone attempting to obtain Drupal by downloading it's source and running composer install couldn't.
  4. Many other developers who tried to build their websites were similarly left disappointed.

This seems to be a risk that comes with dependency management, and raises the question of should vendor be committed to version control? I'm hoping that this post will help you answer that.

Read more

DrupalCamp Bristol 2017

Drupal has a thriving community in Bristol and the south-west, and they've put on some excellent events over the last few years. Last weekend they had their third DrupalCamp Bristol, and I was fortunate to be able to attend and speak.

Read more

Nicer date ranges in Drupal – part 3

This is the last part of a series on improving the way date ranges are presented in Drupal, by creating a field formatter that can omit the day, month or year where appropriate, displaying the date ranges in a nicer, more compact form:

In this post we look at adding an administrative interface, so site builders can add and edit formats from Drupal's UI.

Read more

Nicer date ranges in Drupal – part 2

This is the second part of a series on improving the way date ranges are presented in Drupal, by creating a field formatter that can omit the day, month or year where appropriate, displaying the date ranges in a nicer, more compact form, e.g.:

This post covers some of the work to make the format customisable, and suitable for release as a contributed module:

Read more

Nicer date ranges in Drupal – part 1

A while ago I wanted to present events with a date range on a Drupal 7 site. Drupal's contributed date module provided a way to store the data, but the display wasn't to my liking, always showing the complete start and end date.

Wouldn't it be nice to show the dates in a more compact fashion, by not repeating the day, month or year where they aren't necessary? Like this:

There didn't seem to be a contributed module available, so I wrote some bespoke code for the project. It only supports one particular UK-specific date format, and there's no support for different languages.

Over the last few days, I've spent some time porting it to Drupal 8 and improving it, suitable for release as a new contributed module.

I thought I'd write about this process in the form of a tutorial over a few posts. I hope you'll find it useful.

Read more

DrupalCamp London 2017 - Sunday

This weekend I’ve been at the fifth DrupalCamp London - a gathering of 500 or so designers, developers and business owners using Drupal.

I blogged previously about the CxO day on Friday and day 2 on Saturday. Today was the final day!

Read more

DrupalCamp London 2017 - Saturday

This weekend I’ve been at the fifth DrupalCamp London - a gathering of 500 or so designers, developers and business owners using Drupal.

Friday was the CxO day, which I blogged about earlier. Saturday and Sunday are more technically focussed.

Read more

DrupalCamp London CxO day

This year is the fifth DrupalCamp London, and today was my first time attending the CxO day. The CxO day is a single track event aimed at business leaders who provide Drupal services. I reckon there were about 100 people there, and more will come over the weekend.

It’s great that DrupalCamps cater for a wide audience, but I can’t help wonder if a separate CxO day leads to a bit of a divide between business and technical. I’d love to hear more talks that cross this divide. There must be many people who could share and learn from each other but don’t get to meet.

Read more

Speaking at DrupalCon

In September last year I gave a talk at DrupalCon in Dublin, on the topic of offline first. I wanted to reflect a little on that experience.

The topic covered how modern browsers allow us to build websites to work better under poor or non-existent network conditions. I chose this because my previous experience writing native mobile apps has given me some insight into the issues with mobile connectivity. Until recently, that’s something that native apps have generally been better at addressing than the web, but now that’s changing.

Read more

A first look at layouts in Drupal core

Today, I started looking at some of the proposals to include layouts within Drupal core from version 8.3 onwards.

This initiative aims to take the functionality that currently exists for laying out blocks and regions, and to use it for displaying other things, such as content entity view and form modes.

Read more

Unconference

On Saturday I took a trip up to Manchester for an unconference organised by the North West Drupal user group.

An unconference is like a conference, but without a pre-planned programme. You go, ideally prepared to speak about a topic or lead a discussion, and the schedule is defined on the day. It’s a great environment for anyone new to public speaking, or for trying out a new talk. You needn’t worry about small audiences either - sessions often naturally turn into discussion groups.

Read more

CMI masterclass

Yesterday I was fortunate to attend a masterclass on Drupal 8’s configuration management initiative, led by Alex Pott.

The configuration management initiative (CMI) is one of the largest changes from Drupal 7 to 8. Many of the techniques and workarounds that we as Drupal developers and site builders had established for Drupal 7 don’t apply or are very different, and the Drupal community is still figuring much of this out.

Alex Pott is one of the core maintainers of Drupal and the CMI lead, so it was great to be able to pick his brains!

Read more