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?

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
| improve this answer | |
  • thanks Brad - is there a list of events for future ref? – Steven Grant Apr 23 at 8:06
  • 1
    Not currently... easiest to search the Craft source for const EVENT_ to see them all. – Brad Bell Apr 26 at 3:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.