- 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 7:36pm 9 February 2024 - πΊπΈ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.