Send a notification to the admin and the user when a registration has been deleted.

Created on 25 January 2024, 10 months ago
Updated 23 February 2024, 9 months ago

Problem/Motivation

I hope I'm not overlooking the function. How can I set hook so that an e-mail is sent automatically when a registrant cancels their appointment or an admin cancels the appointment?

πŸ’¬ 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

    You could approach this similarly to how you did it when a registrant was created in πŸ’¬ How to send a notification e-mail to the admin when a registration has been made? Fixed , but instead use the YOUR_MODULE_registrant_delete hook.

  • πŸ‡©πŸ‡ͺGermany trichers

    Thanks for the helpful hint.
    I have now implemented the whole thing like this:

    First I added a notification_type:

    function terminbuchung_recurring_events_registration_notification_types_alter(array &$notification_types) {
        'delete_registration_notification' => [
          'name' => t('Delete Registration Notification'),
          'description' => t('Send an email to an admin when someone deletes a registration for an event'),
        ],        
      ];
    }
    

    Then the function:

    function terminbuchung_registrant_delete(EntityInterface $entity) {
      $key = 'delete_registration_notification';
      $to = 'YOURMAIL';
      $params = [
        'registrant' => $entity,
      ];
      $currentDateTime = new DateTime();
      $dateString = $params['registrant']->field_reg_datum_start->value;
      $dateTime = new DateTime($dateString);
        
      if ($currentDateTime <= $dateTime) {
        $mail = \Drupal::service('plugin.manager.mail');
        $mail->mail('recurring_events_registration', $key, $to, \Drupal::languageManager()->getDefaultLanguage()->getId(), $params);
      }
    }
    

    By querying the date, I prevent an e-mail from being sent when past registrations are deleted. I think this is necessary so that an e-mail is not sent to all deleted registrations when an event series is deleted.

  • πŸ‡ΊπŸ‡ΈUnited States owenbush Denver, CO

    Great stuff! I am glad you got it to work.

  • Status changed to Fixed 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States owenbush Denver, CO

    I'll close this out as it seems to be working for you.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024