<p>Could you try this:</p>
<pre><code> Event::on(
        Entry::class,
        Entry::EVENT_BEFORE_SAVE,
        function (ModelEvent $event) {
            if (ElementHelper::isDraft($event-&gt;sender)) {
                // ...
            }
        }
    );
</code></pre>
<p>Also you can configure it here:
<a href="https://craftcms.com/docs/3.x/extend/events.html" rel="nofollow noreferrer">https://craftcms.com/docs/3.x/extend/events.html</a></p>
<p><a href="https://i.sstatic.net/M72J1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/M72J1.png" alt="enter image description here" /></a></p>
<p>Or you can try this:</p>
<pre><code>use craft\events\ModelEvent;
use craft\models\EntryDraft;
use yii\base\Event;

...
Event::on(
    EntryDraft::class,
    EntryDraft::EVENT_BEFORE_SAVE,
    function (ModelEvent $event) {
        if ($event-&gt;sender-&gt;firstSave) {
            // ...
        }
    }
);
</code></pre>

CC BY-SA 4.0
2023-08-21T06:10:50.187Z
It's work for craft4, but my craft version is craftcms/cms : 3.6. So, please guide for craft3, Thank you.
arshit kalkani
CC BY-SA 4.0
2023-08-21T14:58:52.737Z
@arshitkalkani What part of the code is exactly not working?
Also, you can try `->isNew` instead of `->firstSave` instead?
RomanAvr
CC BY-SA 4.0
2023-08-09T19:08:30.500Z
2023-08-09T19:46:51.857Z
2023-08-09T19:46:51.857Z
RomanAvr
<p>craftcms/cms : 3.6</p>
<p>First create new entry and it store as draft</p>
<p>then i publish this entry</p>
<p>then create a new draft version of this published entry</p>
<p>so how to differentiate this is first draft or second draft in &quot;ModelEvent&quot;?</p>
<pre><code>Event::on(Entry::class, Element::EVENT_BEFORE_SAVE, function(ModelEvent $e) { });
</code></pre>

<craft3>
How to differentiate between draft versions in ModelEvent?
# How to differentiate between draft versions in ModelEvent?

(Asked by: username_0 on 2023-08-04)

craftcms/cms : 3.6
First create new entry and it store as draft
then i publish this entry
then create a new draft version of this published entry
so how to differentiate this is first draft or second draft in "ModelEvent"?
Event::on(Entry::class, Element::EVENT_BEFORE_SAVE, function(ModelEvent $e) { });

**Tags:** craft3


---

## 1 answers

### Answer by username_1 on 2023-08-09. Score: 1

Could you try this:
 Event::on(
        Entry::class,
        Entry::EVENT_BEFORE_SAVE,
        function (ModelEvent $event) {
            if (ElementHelper::isDraft($event->sender)) {
                // ...
            }
        }
    );

Also you can configure it here:
https://craftcms.com/docs/3.x/extend/events.html

Or you can try this:
use craft\events\ModelEvent;
use craft\models\EntryDraft;
use yii\base\Event;

...
Event::on(
    EntryDraft::class,
    EntryDraft::EVENT_BEFORE_SAVE,
    function (ModelEvent $event) {
        if ($event->sender->firstSave) {
            // ...
        }
    }
);

> **Comments:**
> **username_0**: It's work for craft4, but my craft version is craftcms/cms : 3.6. So, please guide for craft3, Thank you.  
> **username_1**: @arshitkalkani What part of the code is exactly not working? Also, you can try `->isNew` instead of `->firstSave` instead?  

---

