Weesperstraat 61-105
1018 VN Amsterdam
The Netherlands

'Simple Like Button' released as Drupal module | A technical explanation on the custom AJAX form -and custom entity implementation.

31 Jul, 2020 Drupal
screenshot like button

During the development of Lucius I build quite a lot of features, that are embedded in the product (an open source Drupal distribution). But we figured some of these might come in handy for other Drupal site owners to use, outside of the OpenLucius Drupal install profile.

So this is the first release I did: Simple Like Button, a very simple like button Drupal module that works in two steps:

  1. Install module
  2. Place block
  3. Done!

Features

  • Instant feedback for end-user: count likes +1 or -1
  • Adds names of users that liked the content
  • It's compatible with all (custom) entities and bundles
  • Compatible with all 'authenticated' roles, not with 'anonymous'.
  • (non feature) Not compatible with Views at the moment.

Built with custom Drupal AJAX form

It's built with a custom AJAX Form, so we don't have to worry about building a custom AJAX route, a CSRF token and custom Javascripts to handle the user interactions.

While CSRF access checking looks like it can be easily integrated via xyz.routes.yml, ajax form was still more easy to implement.

Downside is that all forms can be cached, in high content site can lead up to unnecessary caching data.

And if you disagree on this approach, please let me know in the comments.

So anyway, if you are looking for a compact example of implementing an AJAX Form, check out the code of this module or the example in this blog.

Built with a Drupal custom entity

We used a Drupal entity for easy management of data:

  • Defining the data model and database table, easy installable.
  • CRUD: the Create, Read, Update and Delete queries are just easy if you work with Drupal entities.

So if you are looking for a compact example of implementing a custom entity, check out the code of this module.

And if you disagree on using a custom Drupal entity here, please let me know in the comments below.

Download the module

Please check out the project page on Drupal.org

Written by Joris Snoek | Jul 31, 2020
Drupal project? Let's Talk

Please tell me all about your project!
Mail , or send a message:

Got some more time?

Related content

09 Oct 2026 Drupal

**There's an incredible amount of things happening in the world of AI and Drupal. Very exciting, but almost impossible to keep up with. I've been planning to seriously dive into agentic coding for a while now. I feel a little late to the party, but at the same time, I get the impression that many…

Read more →

28 Sep 2026 Drupal

AI as a programming partner

A request from a product owner: their Drupal website has a content type called 'Event'. The editorial team wants to display a block on the homepage showing the next three events. ## The initial request and AI prompt > “Create a Drupal block that displays the next three events, sorted by start…

Read more →

21 Sep 2026 Drupal

With new features like: @-mentions, drag-and-drop images & general settings.

Last week we released a new version of OpenLucius: a lean and fast Drupal social collaboration distribution with features like: groups, social posts, messages, group chats, stories, file -and folder management, notebooks, categories, activity streams, notifications, @-mentions, comments and…

Read more →

14 Sep 2026 Drupal

Save time, frustration, and potential content loss.

Read more →