Skip to content

Event to skip saving a revision #16260

Closed Answered by brandonkelly
ryssbowh asked this question in Ideas
Discussion options

You must be logged in to vote

Just made this possible for Craft 5.6: (0aa4936)

use craft\elements\Entry;
use craft\events\RevisionEvent;
use craft\services\Revisions;
use yii\base\Event;

Event::on(
    Revisions::class,
    Revisions::EVENT_BEFORE_CREATE_REVISION,
    function(RevisionEvent $event) {
        if (
            $event->canonical instanceof Entry &&
            $event->canonical->section?->handle === 'myHandle' &&
            Craft::$app->request->isSiteRequest
        ) {
            // avoid creating a revision
            $event->handled = true;
        }
    }
);

Note that setting $event->handled = true will only prevent a revision from getting created if at least one revision already exists for the …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ryssbowh
Comment options

Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants