Recent Blog Posts

Making a contributing module for fighting spam

By Ronald van Belzen | May 9, 2018

Making a new module starts with an idea for the module. In this case it was trying to make a module that can replace Mollow to some extend (see previous blog post).

Finding a name for your module can be a challenge, but whatever name you pick, be sure that the machine name of your module is available. Try whether the project exist by visiting{my_module_name}. A page not found (404) response is a good enough indicator to confirm that your module name is still available.

Next step is to read the documentation. The best starting point seems to be Contribute to development. To gather all the information you need to follow half a dozen links, but as far as I can tell all the information is there.

I had a look at the Mods & Plugins that make use of the service provided by Stop Forum Spam, and the concensus seems to be to name the mod after the service it makes use of. So I went for the name Stop Forum Spam Client. Don't go there before I finish this series of articles. I will release a fully functional and tested version soon after that.

name: 'Stop Forum Spam Client'
type: module
description: 'Client that makes use of the api services for blocking spam, spammers and spambots.'
configure: sfs.settings_form
package: 'Spam control'
version: '1.0'
core: '8.x'

As you can see in the above info file the module has no dependencies, while the module may depend on the presence of some modules, but must be able to be installed in their absence. The configuration setting form will imediately show a way to solve this dilemma. And what these modules are will become clear when looking at the configuration install parameters.

Fighting Spam

By Ronald van Belzen | May 7, 2018

I was a satisfied user of the Mollom module, but unfortunately nothing lasts forever, and about a year ago it was announced that the service would be discontinued. Not long ago the moment arrived and my site was hit by spam. It was time to look for an alternative for Mollom.

Jeff Geerling wrote quite a good article in which he found his replacement for Mollom: CleanTalk. It is not free, but relative cheap. According to Jeff it has some restrictions but it fulfills his requirements and works like a charm.

Personally, I have been a years long follower of the StopForumSpam site and did remember the existence of the SpamBot module for Drupal 7, that has been ported to Drupal 8 (and is still in beta, but it works). The only restriction of the SpamBot module is that it is designed to stop spammers from registering  and nothing more. The drupal 7 version can also report spammers (the port to Drupal 8 is missing the latter functionality), but it certainly is not a full replacement for Mollom. However, something is better than nothing, so I gave it a try.

Together with the Honeypot module and the Captcha module it is quite effective, so I cannot complain. But, as is so often the case, I want more. Like: being able to block spammers/spambots from posting content and comments (and the ability to report the spammers that get through to StopForumSpam). Maybe I can develop that myself. If I would manage to include blocking spam to Webform I think that would be a decent alternative for Mollom. Maybe it is not even that hard to do.

So, I decided to find out, and keep you posted of my progress.

Turn Drupal 8 into an Identity Provider (continued)

By Ronald van Belzen | December 13, 2017

In a previous blog post I described how to turn a Drupal 8 installation into a Identity Provider (IdP) by configuring SimpleSAMLphp. The configuration files where placed in a subdirectory of the vendor map, which is something you really should not do when you are using Composer to install and update your Drupal installation.

Move the configuration files

When you move these configuration files to another location SimpleSAMLphp should be told about it. For this purpose the environment variable SIMPLESAMLPHP_CONFIG_DIR exists. To my experience the best way to set this variable is in the Apache vhost.conf file. In my case I moved the configuration files to /var/www/drupalvm/drupal/web/sites/default/simplesamlphp:

<VirtualHost *:80>
  DocumentRoot "/var/www/drupalvm/drupal/web"
  Alias /simplesaml "/var/www/drupalvm/drupal/vendor/simplesamlphp/simplesamlphp/www"
  SetEnv SIMPLESAMLPHP_CONFIG_DIR "/var/www/drupalvm/drupal/web/sites/default/simplesamlphp"
  <Directory "/var/www/drupalvm/drupal/web">
    AllowOverride All
    Options -Indexes +FollowSymLinks
    Require all granted
  <FilesMatch \.php$>
    SetHandler "proxy:fcgi://"

The files 'config.php' and 'authsources.php' are placed in this subdirectory (not is a subdirectory ./config of this subdirectory).

In this subdirectory the subdirectories ./cert, ./metadata and ./modules are created. The ./cert subdirectory contains the certificates we created in the previous blog post. The ./metadata subdirectory contains the files 'saml20-idp-hosted.php' and 'saml20-sp-remote.php' that were also created in the previous blog post. The ./modules directory just contains the ./modules/drupalauth subdirectory with the empty file 'default-enable'.

Next we need to tell SimpleSAMLphp where to find the certificates and the metadata in the 'config.php':

Turn Drupal 8 into an Identity Provider with SimpleSAMLphp

By Ronald van Belzen | December 11, 2017

There is enough information available to help you turn a Drupal 7 installation into an Identity Provider (IdP) for Single Signon (SSO) and Single Logout (SLO). In fact that information will help you with accomplishing the same for Drupal 8. However, the amount of configuring that is involved to accomplish this might be too daunting for someone starting out on this venture.

Personally the following links helped me on the way:

The latter delivers a Drupal 7 module and a SimpleSAMLphp module written for Drupal 7 and instructions on how to configure these. They are the same modules used by the author of the blog post in the first link.

Brad Jones has programmed a module inspired by the work done by Steve Moitozo for Drupal 7 (Drupalauth module): saml_idp. This blog describes how to use saml_idp to turn your Drupal 8 installation into an IdP.


The saml_idp module that will be installed with Composer depends on openid/php-openid, which in turn requires the PHP extension GMP to be installed. Most standard PHP installations do not include this extension. You may need to install it first. In my situation I used the Linux shell command:

sudo apt-get install php7.1-gmp

After restarting the webserver the module can be installed using Composer:

composer require drupal/saml_idp

The installation description for saml_idp advises you to run the post installation script. You can do this with Drush from the web root with the command:

drush ev 'Drupal\saml_idp\Install::postInstall()'

What this post installation script does is create the subdirectory /vendor/simplesamlphp/simplesamlphp/modules/drupalauth and in that subdirectory create an empty file with the name 'default_enable'.

Upload an Image File using REST API in Drupal 8

By Ronald van Belzen | December 8, 2017

Currently there is no support to directly upload images using REST in Drupal 8 ( The work-around that I describe here uses Base64 encoded images to accomplish the upload of an image using REST.

For a decoupled Drupal 8 installation I needed to upload an avatar image for a user. Since I started with a minimal installation of Drupal 8, I first had to enable the image and field_ui modules and added an image field to the user entity that I named 'avatar' (with the machine name 'field_avatar'). I also created three new image styles specifically to be used for this image style (machine names: 'avatar_large', 'avatar_medium' and 'avatar_small').

Next, I installed the restui module and enabled the modules basic_auth, rest, restui and serialization before starting on my own module. The info file 'web/modules/custom/mymodule/':

name: MyModule REST Services
type: module
description: "MyModule REST Service Resources"
package: Web services
  - rest
core: '8.x'

The helper class that I created to handle most of the functionality is displayed in full below, but will be explained as we make use of its functionality ('web/modules/custom/mymodule/src/Base64Image.php'):