Handling Entry Saves

As of Craft 3.2, drafts and revisions are now elements just like published entries.

If your plugin or module was registering a listener for an entry’s Element::EVENT_BEFORE_SAVE or Element::EVENT_AFTER_SAVE, you may want to avoid multiple saves by first checking whether the element is a draft or revision as opposed to a published entry:

use craft\base\Element;
use craft\elements\Entry;
use craft\events\ModelEvent;
use craft\helpers\ElementHelper;
use yii\base\Event;

Event::on(
    Entry::class, 
    Element::EVENT_BEFORE_SAVE, 
    function(ModelEvent $e) {
        /* @var Entry $entry */
        $entry = $e->sender;

        if (ElementHelper::isDraftOrRevision($entry) {
            // don’t do anything with drafts or revisions
            return;
        }
        
        // ...
    }
);

The same applies to Elements::EVENT_BEFORE_SAVE_ELEMENT and Elements::EVENT_AFTER_SAVE_ELEMENT.