<pre><code>Craft::$app-&gt;elements-&gt;on(Elements::EVENT_BEFORE_SAVE_ELEMENT, function(ElementEvent $e) {

    // Make sure it's an entry.
    if ($event-&gt;element instanceof \craft\elements\Entry) {
        $entry = $event-&gt;element;

        // Check if it's in the section you care about
        if ($entry-&gt;sectionId == 1) {
            // Do your custom logic
        }
    }
});
</code></pre>

CC BY-SA 4.0
2020-04-23T08:06:38.273Z
thanks Brad - is there a list of events for future ref?
Steven Grant
CC BY-SA 4.0
2020-04-26T03:36:07.140Z
Not currently... easiest to search the Craft source for `const EVENT_` to see them all.
Brad Bell
CC BY-SA 4.0
2020-04-22T22:48:20.353Z
2020-04-22T22:48:20.353Z
Brad Bell
<p>if that entry is in a particular section, then I want to do some task.</p>

<p>I can't really find the event docs I need to do that. Everything I've come across has been for Craft 2.</p>

<p>Any steps for a hint?</p>

<plugin-development><craft3><events>
Do something on save of an entry
# Do something on save of an entry

(Asked by: username_0 on 2020-04-22)

if that entry is in a particular section, then I want to do some task.

I can't really find the event docs I need to do that. Everything I've come across has been for Craft 2.

Any steps for a hint?

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


---

## 1 answers

### Answer by username_1 on 2020-04-22. Score: 2 | Accepted answer

Craft::$app->elements->on(Elements::EVENT_BEFORE_SAVE_ELEMENT, function(ElementEvent $e) {

    // Make sure it's an entry.
    if ($event->element instanceof \craft\elements\Entry) {
        $entry = $event->element;

        // Check if it's in the section you care about
        if ($entry->sectionId == 1) {
            // Do your custom logic
        }
    }
});

> **Comments:**
> **username_0**: thanks Brad - is there a list of events for future ref?  
> **username_1**: Not currently... easiest to search the Craft source for `const EVENT_` to see them all.  

---

