Hi, I am Teun [nuez]
I am an independent Drupal specialist with over 7 years of experience building websites and web applications.
Hire me

How to unit test methods that create and return entities in Drupal.

March 8, 2018 · 0 minute read

Recently I tried to create a Unit test for a Drupal service that creates and returns entities. In my test I wanted to check if the field values that were used for creating those entities were matching my assertions.

In Drupal , the static ::create method of any content entity returns the created entity. In my unit test, checking the returned entity for values would be a hassle, as I would have to mock and stub my way through all the services that it relies on to fetch those values. More useful would be to mock the entity and let the ::create() method return the values that were just passed as arguments.

┬┐Does that make any sense?

Let me try and explain:

Read more

How to build a super simple availability calendar.

February 15, 2018 · 0 minute read

As a freelancer I like my (potential) clients to be aware of my availability. I decided to build something that would allow me to fill in my availability in Google Calendar, which would then be displayed in a nice widget on the website.

The widget doesn’t need to display anything but whether or not I am available or busy on a certain day. I figured that the good ol’ jQuery Datepicker would do perfectly.

So here’s what I did.

1. Get an API Key.

When you google for accessing the Google API, most forums will point you in the direction of the OAUTH2 protocol. Using OAuth would be necessary if we wanted to access restricted content. For accessing publicly accessible content, the Google API is a lot easier. All you need is an URL and an API key.

Go to https://console.developers.google.com and create a new project. Select credentials and create an API Key. You can restrict the use of the key although you don’t have to. Copy the API key value somewhere: we’ll need it in our code.

Read more

Create computed fields in Drupal 8.

October 1, 2017 · 0 minute read

I have updated this post as a result of the issue (https://www.drupal.org/project/drupal/issues/2392845) that added the ComputedItemListTrait trait to core.

In Drupal 8 we have on the one hand field types with some computed field properties, and on the other hand fields that are fully computed.

Computed field properties are quite common in Drupal 8. An example is the TextItem field type. The properties value and format are stored in the database, but a third property called processed is computed on the fly using the value and the format.

When it comes to fully computed field items, there are less examples in core. It seems that in Drupal 8.5 the only fully computed field is the moderation_state field, provided by the Content Moderation module. The field is added to all entities that add a moderation workflow.

Since the ComputedItemListTrait was added in this issue, however, adding a computed field has become A lot more straightforward than it seems.

Read more

Hugo vs Drupal: Why I used Hugo for my Drupal portfolio website.

August 1, 2017 · 0 minute read

Drupal is a full-fledged CMS for secure and complex websites and applications and is adopted by many big companies and governments accross the globe. Hugo is a static site generator built in GoLang that is blazing fast and quickly gaining popularity. For this website about my Drupal work I decided to go for Hugo. Here’s why.

Read more

© 2018 - Teun van Veggel