add AttendanceCertificateEvent symfony event
Adds a Symfony Event broadcast when an attendance certificate is about to be generated. This allows implementers to conditionally choose a message template id in custom extensions. To use: Add an event subscriber in a custom extension. Example, create file in <extension_dir>/Civi/Event/Subscriber named AttendanceEventSubscriber.php
<?php
namespace Civi\Event\Subscriber;
use Civi\Certificates\Event\AttendanceCertificateEvent;
use Civi\Core\Service\AutoSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Civi\Api4\Participant;
/**
* This requires <mixin>scan-classes@1.0.0</mixin> in the extension info.xml in the <mixins> area.
* @service
* @internal
*/
class AttendanceEventSubscriber extends AutoSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents(): array {
return [
'civi.certificates.attendance' => 'determineMessageTemplateID',
];
}
/**
* @param \Civi\Certificates\Event\AttendanceCertificateEvent $event
*/
public function determineMessageTemplateID(AttendanceCertificateEvent $event): void {
$contact_id = $event->getContactId();
$participant_id = $event->getParticipantId();
$event_id = $event->getEventId();
$message_template_id = $event->getMessageTemplateId();
$event->setMessageTemplateID(999);
}
}
Make sure the extension info.xml has the scan-classes mixin specified
<mixins>
<mixin>scan-classes@1.0.0</mixin>
</mixins>