<p>We just released Craft 3.2.5 which should fix this for you.</p>

<p>For more context about why this happened in the first place, see <a href="https://github.com/craftcms/cms/issues/4589" rel="nofollow noreferrer">https://github.com/craftcms/cms/issues/4589</a>.</p>

CC BY-SA 4.0
2019-12-05T18:55:10.653Z
Useful also to add that you need to check for draft/revision using `ElementHelper`: https://github.com/craftcms/cms/issues/4621#issuecomment-513485799
iamkeir
CC BY-SA 4.0
2019-07-19T17:54:49.170Z
2019-07-19T17:54:49.170Z
Brandon Kelly
<p>Pre Craft 3.2, you could do something like this if you wanted to perform an action in the event you just saved a new entry:</p>

<pre><code>use craft\elements\Entry;
use craft\events\ModelEvent;

Event::on(
    Entry::class,
    Entry::EVENT_AFTER_SAVE,
    function(ModelEvent $event) {
        $entry = $event-&gt;sender;
        $isNew = $event-&gt;isNew;

        if ($isNew) {
            // do something...
        }
    }
);
</code></pre>

<p>However, after the update, this code doesn't work as it used to. <code>$isNew</code> always gets evaluated to <code>true</code> whether resaving a pre existing entry or editing a yet-to-be-saved entry (the autosave kicks in after a couple of seconds while you're editing).</p>

<p>I've tried doing something like this to check if the entry is being resaved but it still gets evaluated to <code>true</code>:</p>

<pre><code>$isBrandNew = false;
if ($event-&gt;isNew &amp;&amp; ! $entry-&gt;propagating &amp;&amp; ! $entry-&gt;resaving) {
    $isBrandNew = true;
}

if ($isBrandNew) {
    // do something
}
</code></pre>

<p>How do I fix this so that my code only runs after a <em>brand new</em> entry was just created, like it did before Craft 3.2?</p>

<plugin-development><craft3><events>
$event->isNew not working as expected after Craft 3.2 update
# $event->isNew not working as expected after Craft 3.2 update

(Asked by: username_0 on 2019-07-19)

Pre Craft 3.2, you could do something like this if you wanted to perform an action in the event you just saved a new entry:
use craft\elements\Entry;
use craft\events\ModelEvent;

Event::on(
    Entry::class,
    Entry::EVENT_AFTER_SAVE,
    function(ModelEvent $event) {
        $entry = $event->sender;
        $isNew = $event->isNew;

        if ($isNew) {
            // do something...
        }
    }
);

However, after the update, this code doesn't work as it used to. $isNew always gets evaluated to true whether resaving a pre existing entry or editing a yet-to-be-saved entry (the autosave kicks in after a couple of seconds while you're editing).
I've tried doing something like this to check if the entry is being resaved but it still gets evaluated to true:
$isBrandNew = false;
if ($event->isNew && ! $entry->propagating && ! $entry->resaving) {
    $isBrandNew = true;
}

if ($isBrandNew) {
    // do something
}

How do I fix this so that my code only runs after a brand new entry was just created, like it did before Craft 3.2?

**Tags:** plugin-development, craft3, events


---

## 1 answers

### Answer by username_1 on 2019-07-19. Score: 3

We just released Craft 3.2.5 which should fix this for you.

For more context about why this happened in the first place, see <https://github.com/craftcms/cms/issues/4589>.

> **Comments:**
> **username_2**: Useful also to add that you need to check for draft/revision using `ElementHelper`: https://github.com/craftcms/cms/issues/4621#issuecomment-513485799  

---

