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.
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."
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.
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.
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:
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.
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.
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.