PHP code example of putyourlightson / craft-element-status-events
1. Go to this page and download the library: Download putyourlightson/craft-element-status-events library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
putyourlightson / craft-element-status-events example snippets
use putyourlightson\elementstatusevents\ElementStatusEvents;
use putyourlightson\elementstatusevents\events\StatusChangeEvent;
// ...
Event::on(
ElementStatusEvents::class,
ElementStatusEvents::EVENT_STATUS_CHANGED,
function(StatusChangeEvent $event) {
$oldStatus = $event->statusBeforeSave;
$newStatus = $event->element->getStatus();
$isLive = $event->changedToPublished();
$isDeath = $event->changedToUnpublished();
$isScheduled = $event->changedTo('pending');
}
);
php craft element-status-events/scheduled