Event to skip saving a revision #16260
-
Would be useful to allow developers to not save a revision based on an event. My use case is the following : I have one section that users are allowed to save on the frontend, there's one field in there that I need admins to see the history of, all the rest we don't care about. With such an event I can calculate field changes myself and skip the revision if needed. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 |
Beta Was this translation helpful? Give feedback.
Just made this possible for Craft 5.6: (0aa4936)
Note that setting
$event->handled = true
will only prevent a revision from getting created if at least one revision already exists for the …