Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-21T06:10:50.187Z
Answers.Text: It's work for craft4, but my craft version is craftcms/cms : 3.6. So, please guide for craft3, Thank you.
Answers.UserDisplayName: arshit kalkani
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-21T14:58:52.737Z
Answers.Text: @arshitkalkani What part of the code is exactly not working?
  Also, you can try `->isNew` instead of `->firstSave` instead?
Answers.UserDisplayName: RomanAvr
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-09T19:08:30.500Z
Answers.LastActivityDate: 2023-08-09T19:46:51.857Z
Answers.LastEditDate: 2023-08-09T19:46:51.857Z
Answers.UserDisplayName: RomanAvr
Body: <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>
  
Tags: <craft3>
Title: How to differentiate between draft versions in ModelEvent?
ThreadText: # 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>
  
  [![enter image description here](https://i.sstatic.net/M72J1.png)](https://i.sstatic.net/M72J1.png)
  
  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**: @username_0 What part of the code is exactly not working? Also, you can try `->isNew` instead of `->firstSave` instead?  
  
  ---
  
  