BeforeAttendeeDownloadSentEvent

The PSR-14 event \OliverKlee\Seminars\Controller\Event\BeforeAttendeeDownloadSentEvent gets triggered after the stream with the contents for a file download for an attendee has been created, but before the stream gets returned with the HTTP response.

Listeners may provide a stream with different contents if desired, for example for adding a watermark or logo.

Example

Registration of the event listener in the extension's Services.yaml:

EXT:my_extension/Configuration/Services.yaml
services:
  # Place here the default dependency injection configuration

  MyVendor\MyExtension\EventListener\Controller\EventListener\Controller\BeforeAttendeeDownloadSentEventListener:
    tags:
      - name: event.listener
        identifier: 'generate-pdf-for-download-with-watermark'
Copied!

The corresponding event listener class:

EXT:my_extension/Classes/EventListener/Controller/BeforeAttendeeDownloadSentEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\EventListener\Controller;

use OliverKlee\Seminars\Controller\Event\BeforeAttendeeDownloadSentEvent;

/**
 * Provides a modified PDF for the attendee download.
 */
final class BeforeAttendeeDownloadSentEventListener
{
    public function __invoke(BeforeAttendeeDownloadSentEvent $event): void
    {
        $contentStream = $event->getContentStream();

        // Here you would modify the content stream as needed.
        // For example, you could add a watermark or modify the PDF content.

        // Set the modified content stream back to the event.
        $event->setContentStream($contentStream);
    }
}
Copied!