How to send a notification e-mail to the admin when a registration has been made?

Created on 10 December 2023, 11 months ago
Updated 17 December 2023, 11 months ago

After a registration has been made, an e-mail should be sent to the admin. It is best to have different e-mail addresses for each bundle.

πŸ’¬ Support request
Status

Fixed

Version

2.0

Component

Recurring Events Registration (Submodule)

Created by

πŸ‡©πŸ‡ͺGermany trichers

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @trichers
  • πŸ‡ΊπŸ‡ΈUnited States owenbush Denver, CO

    At the moment, there is no mechanism in place to send emails to an administrator when a registration is made.

    If you wanted to be able to customize the message sent out in the Drupal admin, you could implement the following hook:

    hook_recurring_events_registration_notification_types() to add a new notification type, for example 'admin_registration_notification'. See the recurring_events_registration.module file for how this is done.

    /**
     * Implements hook_recurring_events_registration_notification_types_alter().
     */
    function recurring_events_registration_recurring_events_registration_notification_types_alter(array &$notification_types) {
      $notification_types += [
        'admin_registration_notification' => [
          'name' => t('Admin Registration Notification'),
          'description' => t('Send an email to an admin when someone registers for an event?'),
        ],
      ];
    }
    

    Then you could probably implement hook_ENTITY_TYPE_insert() with ENTITY_TYPE being 'registrant', with something like this:

    use Drupal\Core\Entity\EntityInterface;
     
    /**
     * Implements hook_ENTITY_TYPE_insert().
     */
    function YOUR_MODULE_registration_insert(EntityInterface $entity) {
      $key = admin_registration_notification';
      $to = 'your-admin-email@domain.com';
      $mail = \Drupal::service('plugin.manager.mail');
      $params = [
        'registrant' => $entity,
      ];
      $mail->mail('recurring_events_registration', $key, $to, \Drupal::languageManager()->getDefaultLanguage()->getId(), $params);
    }
    
  • πŸ‡©πŸ‡ͺGermany trichers

    Thanks for this fast and great feedback!

    I had to correct one thing

    function YOUR_MODULE_registration_insert(EntityInterface $entity) {

    It does not have to be registration_insert, but registrant_insert, then it works.

    use Drupal\Core\Entity\EntityInterface;
     
    /**
     * Implements hook_ENTITY_TYPE_insert().
     */
    function YOUR_MODULE_registrant_insert(EntityInterface $entity) {
      $key = 'admin_registration_notification';
      $to = 'your-admin-email@domain.com';
      $params = [
        'registrant' => $entity,
      ];
    
      $mail = \Drupal::service('plugin.manager.mail');
      $mail->mail('recurring_events_registration', $key, $to, \Drupal::languageManager()->getDefaultLanguage()->getId(), $params);
    }
    
  • πŸ‡ΊπŸ‡ΈUnited States owenbush Denver, CO

    Ah yes, sorry. Great catch. I am glad it works for you!

  • Status changed to Fixed 11 months ago
  • Status changed to Fixed 11 months ago
Production build 0.71.5 2024