Hire for Craft CMS

Events

Four events, on justinholtweb\hire\services\Applications, around the two paths every application goes through.

EventClass
EVENT_BEFORE_SUBMITSubmitApplicationEventCan refuse the application
EVENT_AFTER_SUBMITSubmitApplicationEventThe application is saved and has an ID
EVENT_BEFORE_STAGE_CHANGEStageChangeEventCan keep the application where it is
EVENT_AFTER_STAGE_CHANGEStageChangeEventThe move is done
use justinholtweb\hire\events\SubmitApplicationEvent;
use justinholtweb\hire\events\StageChangeEvent;
use justinholtweb\hire\services\Applications;
use yii\base\Event;

// Refuse an application before it's saved. Add an error to say why — the visitor sees it.
Event::on(Applications::class, Applications::EVENT_BEFORE_SUBMIT, function(SubmitApplicationEvent $event) {
    if (str_ends_with($event->application->email, '@competitor.example')) {
        $event->application->addError('email', 'Please apply through your recruiter.');
        $event->isValid = false;
    }
});

// Push a new application to your HR system.
Event::on(Applications::class, Applications::EVENT_AFTER_SUBMIT, function(SubmitApplicationEvent $event) {
    // $event->application has an ID; $event->job is the advert.
});

// React to a move. `from` and `to` are Stage models, null for the inbox.
Event::on(Applications::class, Applications::EVENT_AFTER_STAGE_CHANGE, function(StageChangeEvent $event) {
    if ($event->to?->isHired()) {
        // Start onboarding for $event->application.
    }
});

A "before" event that sets $isValid = false without adding an error still shows the visitor a message. The "after" events fire once the history entry is written, counts are adjusted and emails are sent.