AfterSaveJobEvent 

\FGTCLB\AcademicJobs\Event\AfterSaveJobEvent is owned by this extension. It decides what happens to the visitor after a job was submitted through the Job Form: which page they are sent to, and whether the confirmation is queued as a flash message.

When it is dispatched 

The Job Form dispatches the event once for every job it saved, in the action that receives the submission. By then:

After the event the form uses the deprecated plugin.tx_academicjobs.settings.listPid when the listeners left no redirect page, sends the notification mail, queues the confirmation as the mode says and redirects, to the redirect page or back to the form.

What a listener reads and changes 

Method Returns
getJob() The saved job, \FGTCLB\AcademicJobs\Domain\Model\Job .
getRequest() The request that submitted the form.
getCurrentPageId() The uid of the page that shows the form.
getSettings() The settings of the plugin: the options of the content element over the TypoScript of plugin.tx_academicjobs.settings and plugin.tx_academicjobs_newjobform.settings .
getRedirectPageId() , setRedirectPageId() The uid of the page the visitor is sent to, or null for none. A page id of 0 or below counts as no page.
getFlashMessageCreationMode() , setFlashMessageCreationMode() Whether the confirmation is queued, a case of \FGTCLB\AcademicBase\Form\FlashMessageCreationMode : ALWAYS , NEVER or SUPPRESS_WITH_CONFIGURED_REDIRECT_PAGE , which queues it unless the visitor is sent to another page than the one of the form.

Both setters return the event.

Example: a confirmation page for theses 

A site accepts jobs and theses through one form. Companies that offer a thesis should land on a page that explains how the supervision by a professor is arranged, everyone else on the general thank-you page of the content element. The page of its own carries its text, so no confirmation message is queued for it.

The page is a TypoScript setting of the project, so it is part of the settings the event hands over:

TypoScript setup
plugin.tx_academicjobs.settings.thesisConfirmationPageId = 42
Copied!
EXT:my_extension/Classes/EventListener/RedirectSubmittedThesis.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\EventListener;

use FGTCLB\AcademicBase\Form\FlashMessageCreationMode;
use FGTCLB\AcademicJobs\Event\AfterSaveJobEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;

final class RedirectSubmittedThesis
{
    private const JOB_TYPE_THESIS = 3;

    #[AsEventListener(identifier: 'my-extension/redirect-submitted-thesis')]
    public function __invoke(AfterSaveJobEvent $event): void
    {
        if ($event->getJob()->getType() !== self::JOB_TYPE_THESIS) {
            return;
        }
        $pageId = (int)($event->getSettings()['thesisConfirmationPageId'] ?? 0);
        if ($pageId <= 0) {
            return;
        }
        $event->setRedirectPageId($pageId);
        $event->setFlashMessageCreationMode(FlashMessageCreationMode::NEVER);
    }
}
Copied!

Rules and pitfalls 

The job is saved already. A listener cannot stop the save or reject the job. The checks of a submission belong in the validation settings. A change a listener makes to the job, or to another record, through a repository is persisted by the form before it redirects, so the listener does not have to persist it itself.

A later listener reads what an earlier one set. getRedirectPageId() returns the value the previous listener handed in, a page id of 0 or below included. Order listeners with the before and after arguments of the attribute when two of them decide the page.

A page id of 0 or below is no page. The visitor is then sent back to the page of the form, exactly as when no page was set, and the deprecated list page is not used for it, see Important: A redirect page of 0 or below from a listener means none. The form shows the confirmation above itself there, see Important: The job form returns to its page with the confirmation.

The mail is sent after the event. A listener does not learn whether it could be sent. The confirmation the form queues says so to the visitor.

The confirmation on a redirect page needs a page that renders it. The form shows it for a visitor who returns to the form. For a redirect page, queuing it is all the mode decides, see Where the confirmation is shown.

Introduced in 

The event exists since the first release of the extension. Changed in 2.4:

Changed in 3.0: