About Pseudo-Fields in Drupal

In my current job, I have become more of a Drupal developer than ever. My last position was in a team where I focused on, among other things, front-end development. But now, as a development team of one, I have to wear all the hats. It has been a different kind of learning experience. Previously, the challenges were more about client interactions and project management. Now my challenges are technical. How can I create the requested features, and how can I provide the best possible user experience?

Very early on in my role, I was asked if I could indicate, for each article on our website, the reading time. This is a feature I have seen on Medium. There are at least two contributed modules that supposedly provide this. I tried the Read Time module, but it was buggy and either did not work properly or crashed the website. The module has not been updated in 2 years and is only used by a couple hundred sites, so maybe I should not be surprised. The other option, Node Read Time has been more recently updated, but is also not used on very many websites.

I was able to create a display of read time for articles using a hook_preprocess_node function in my theme based on an example I found online. This worked fine, but it was clumsy. I wanted a way to insert this read time indicator into my node display as neatly as I could any other field in the content type. I forget exactly what it is I tried to Google, but I stumbled on an article describing how to create a pseudo-field.

The pseudo-field option is exactly what I was looking for. It allows me to insert information into the node display like any other entity field and I can designate a theme file for it. If I wanted to get really fancy, I could probably provide some configuration options to adjust the read time calculation, the field being used for the calculation, and the content types on which to display the information. But for now, enough is enough. I was able to write yet another simple custom module that gave me exactly what I needed. That is enough of a win.