DrupalCamp London 2020

18th March 2020 - 9 minutes read time

DrupalCamp London was held on the 14th and 15th March 2020 and I went down to City University London to partake in the event. I wasn't talking this year, so I was there purely to enjoy the conference.

Drupal 8: Theming With Tailwind CSS

8th March 2020 - 13 minutes read time

Upon a recommendation from someone in my local Drupal user group I decided to give Tailwind CSS a go. The ultimate aim of this was to replace the base theme I am using here with a more stripped down theme. At the time of writing this I am using the Cog theme, and whilst it has it's merits, I find that it's a little too much for this simple site.

I decided, therefore, to create a new theme and use Tailwind CSS to alter the site a little. This meant an exercise in integrating Tailwind CSS into a Drupal theme.

Tailwind CSS?

In case you haven't heard of Tailwind CSS I'll quote the site here.

"Tailwind CSS is a highly customizable, low-level CSS framework that gives you all of the building blocks you need to build bespoke designs without any annoying opinionated styles you have to fight to override."

Adventures In FizzBuzz

29th February 2020 - 8 minutes read time

Tests for programmers in an interview process are not uncommon. For the last couple of years I have asked a quick pre-interview question to junior developers to see what sort of stuff they come up with.

As I don't want to set any developer a task that will take longer than absolutely needed I opted to set a very simple task for them. Commonly known as "FizzBuzz", this task is as follows.

"Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz"."

The expected output for this would be something like this.

Inverting A Scale

23rd February 2020 - 3 minutes read time

One technique I find useful, especially when drawing images, is to invert a number on a scale. In PHP, coordinates in an image are drawn from the top left of the image. This means that if we want to draw from the bottom left then we need to invert the y coordinate.

The following is example PHP code that creates an image with a single, diagonal line, drawn across the middle.

Drupal8: Finding All FieldWidget Types

16th February 2020 - 3 minutes read time

Whilst searching for an answer to a problem the other day I found a comment that details a command that prints out all of the FieldWidgets available in Drupal 8. This is useful if you are looking for all of the field widget classes in Drupal8.

Here is the command:

grep -rl '\@FieldWidget' | xargs grep -m1 'id = ' | grep -o FieldWidget.*

This prints out something similar to the following:

Traits Versus Inheritance In PHP

9th February 2020 - 6 minutes read time

The other day I was conducting a code review and found that a developer had used a trait to give two classes the same group of utility methods. Whilst there was nothing wrong with this in terms of functionality, I asked the developer why they had chosen to use traits instead of inheritance. We eventually decided that an inheritance model would be better suited to the situation but I thought I would go through some of the thought processes here.

What Is A Trait?

A trait, if you weren't aware, is like a class, but you don't instantiate it directly. Traits are defined using the trait keyword and are otherwise quite like a class in structure.

The idea is that code is essentially copied into the class you want to use it in from the trait and the class acts like it had that code all along. For example, let's take a simple trait.

Drupal 8: Altering Update Dependencies

7th January 2020 - 6 minutes read time

I perform a lot of Drupal updates, and they mostly go very well. The code updates without incident and the database updates apply whatever updates they need without a hitch. Every now and then, however, I will come across a project that hasn't received updates in a while, which means there are a lot of database updates to run through.

Having Drupal run 100+ database updates across modules and core can be a bit problematic. Some modules will require core updates to happen first, and when this happens out of order the database update update fails spectacularly.

PHP Custom Stream Filters

29th December 2019 - 11 minutes read time
Stream filters allow changes to be made to textual data in streams. This allows text to be changed when writing to or reading from streams, instead of changing the text after the stream has been run. There is a framework built into PHP that allows custom filters to be added to the group of built in filters.

PHP Custom Stream Wrappers

24th December 2019 - 9 minutes read time
Part of the strength of PHP's stream wrappers is the ability to add our own stream wrappers to the list of available wrappers. We can therefore natively open any type of resource just by registering a stream wrapper and then using the normal fopen() functions. The custom stream wrapper functionality is made possible through a few functions built into PHP.

PHP Streams

13th December 2019 - 12 minutes read time

Streams are a way of generalising file, network, compression resources and a few other things in a way that allows them to share a common set of features. I stream is a resource object that has streamable behaviour. It can be read or written to in a linear fashion, but not necessarily from the beginning of the stream.

Streams have been available in PHP for quite a while (at least since version 4.3.0) and are used pretty transparently by most PHP programmers. They can be used to access files, network resources, command line arguments, pretty much anything that goes through the input/output stream in PHP.

I was recently looking at ReactPHP and found that the use of streams was a requirement in order to prevent blocking the input/output stream. Although, I had seen streams being used in PHP applications, I wasn't entirely certain how to use them myself. As a result I thought I'd put together a post about them.