Receive an activity log by email with the Drupal 8 Entity Activity module

A letter box

In a previous post I had the opportunity to present the Entity Activity module which allows us to set up a notification system on any type of Drupal 8 content entity, according to the three main actions of their life cycle: creation, update and deletion.

Since beta version 8, the Entity Activity module includes a sub-module, Entity Activity Mail, which now allows us to send by email a summary of the notifications generated for each user, according to a frequency that can be configured by each user.

General configuration

The module offers several general configuration options.

Entity Activity Mail General settings

The main configuration options, in addition to the possibility of stopping the sending of notifications by email globally, are:

  • The possibility to exclude notifications, which have been marked as read, from the report sent by email
  • The definition of the time at which background tasks will be launched to generate all notification reports for each user, and then generate their sending. The tasks launched can be very time-consuming here depending on the volume of notifications and users, so it is recommended to configure the site cron at the server level so that the Cron is launched at least every hour so that the queues in charge of generating reports and sending reports by email are completely processed.
  • The ability to log the sending of each report for history or debugging purposes.

We also have the possibility to customize the email of the notification report.

Entity Activty Mail mail settings

 

In particular, we can customize the sender mail (leave blank to use the site mail), the subject of the mail, a text displayed before the notification report and finally a text displayed after the report (footer).

It is strongly recommended to use the SwiftMailer module to allow the sending of emails in HTML format, or any other solution at your convenience to ensure that the emails sent are in HTML format, for easier integration and theming of the reports generated and sent.

Configuration for users

In order to allow each user to select the frequency at which they wish to receive the notification report, we must configure the Logs report frequency component on the manage form display of the user entity.

Widget frequency

This component will allow each user to set up their account according to their preferences.

Frequency options

Thus, a user can choose from:

  • Never receive a report by email
  • Receive an email with each generated notification (immediately)
  • Receive a daily, weekly or monthly report.

Theming of the report

The email of the notification report can be themed by overloading the basic template provided by the module: entity-activity-mail-report.html.twig

The basic template render each notification according to the Mail view mode, which you can customize at this level, with the logs_content variable that contains a rendering table of all log entities in this view mode. For more detailed needs, the Twig template has with the logs variable all the Log entities that make up the report. If your needs are more advanced, you can always ask for an intervention from a Drupal Freelance who will most certainly be able to customize the rendering according to your expectations.

By way of conclusion

With a few clicks we can now offer users the option of receiving a notification report according to their preference.

As we have said above, generating and sending these reports by email can be very time-consuming, so the module works in tree steps: first of all it collects all eligible users according to their sending frequency, then for each user a processing queue is in charge of generating the report, then another processing queue is in charge of sending the email itself. These three steps make it possible to generate and send reports more easily, but it should be borne in mind that processing queues are only executed when the site's Cron is launched. This is why it is highly recommended to launch the Cron from the server hosting the site at least every hour, or less depending on the volume (number of users, estimated number of notifications) of your Drupal project.

 

Ajouter un commentaire