Drupal

A Drupal Contribution: The Simple Petition Node Module - Drupal 8

Published on 23 July 2019
petition-module-drupal-8
As part of the redesign of the www.cgt.fr website with Drupal 8, the implementation of a petition management feature was requested.

The contributed Poll module only partially met the requirement, so we developed the Simple Petition Node module to address the need. In this post, we explain the benefits of this module, now available to the Drupal community!

Context

The redesign of the www.cgt.fr website using Drupal 8 required a module to manage petitions (for example: fighting against social injustice at work). The CGT was able to collect nearly 2,500 verified and confirmed signatures. The SPN module made this experience easy, fast, and secure for both users and CGT administrators.

Initially, we turned to the Poll module, which is included by default in Drupal 8. However, it only partially covered our needs. Indeed, Poll offers a way to display poll results but is limited to a single question. Moreover, no other Drupal 8 module provided easy petition management, so we developed our own module, which we've shared on drupal.org.

Module Features

The SPN module offers the following main features:

  • Creation of petitions (form and results blocks are added to the Drupal block list);
  • Displaying the petition block on any chosen page;
  • Front-end display of results for each petition question (in the form of a block showing the total number of signatures);
  • Verification and validation of the email address used to sign, to ensure the contribution is counted, via an automatic validation request email;
  • Customizable confirmation and thank-you message through notification email (the administrator can also choose between 3 message types: expired link or reused email address, signature validation confirmation, and a general error message).

In addition, users can sign a petition whether logged in or anonymous. To submit, they are required to fill in the information requested by the form and may add a comment if necessary.

Module Development and Drupal Standards Compliance

Simple Petition Node (SPN) is a custom module developed in PHP and using Symfony2 / Twig for templating. The module is available in version 8.x – 1.0. We used the reCAPTCHA module to secure form submissions.

As code quality is key for the sustainability and security of a Drupal site, we developed the SPN module in compliance with Drupal standards:

  • The module uses Drupal entities and implements them;
  • The module uses the same method as Drupal for sending emails and notifications, with secure form submissions;
  • Overall, the code follows Drupal standards (naming conventions for functions, variables, classes, etc.)

Installation

SPN can be enabled like any other extension from the Drupal back office: /admin/modules.
During installation, the module creates a "Petition" content type with predefined fields (Title, Body, validation and confirmation emails, and their corresponding domains) and adds two blocks — petition signature form and petition results block, which can be managed in the Drupal back office.

A configuration page is available at /admin/config/spn/notifications to manage default emails and notifications for all petitions. Tokens are available to use variables related to the petition.

Additionally, SPN adds two tables to the Drupal schema: "Petition Signatures" and "Petition Users." The former will hold information on every signature made on a petition, and the latter, information on anonymous users who sign petitions.

What’s Next?

Our team of developers plans to enhance the module over time to offer more advanced features for administrators, particularly for signature management (page/view, etc.).

In the meantime, try it out and share your feedback!... Or collaborate!

Read more articles on Drupal