Triggers events whenever element statuses change in Craft CMS.
Branch: v2
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
CHANGELOG.md
LICENSE.md
README.md
composer.json

README.md

Element Status Events Module for Craft CMS 3

The Element Status Events extension provides events that are triggered whenever an element’s status changes. It is intended to be used a helper component for other Craft modules and plugins.

To get an understanding of how the module works, read the Challenge #6 – The Chicken or the Egg solution.

Requirements

This component requires Craft CMS 3.0.0 or later.

Usage

Install it manually using composer or add it as a dependency to your plugin.

composer require putyourlightson/craft-element-status-events

If you work with scheduled Entries (future published or expired), make sure to set up cron that calls:

php craft element-status-change/scheduled

Events

Whenever an element’s status is changed, ElementStatusEvents::EVENT_STATUS_CHANGED is fired. The StatusChangeEvent object provides information about the change.


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');
    }
);

License

This module is licensed for free under the MIT License.

Created by PutYourLightsOn in cooperation with Oliver Stark