8

I've been looking for an Event Reference doc for Craft 3 just like what we had for Craft 2, but couldn't find one. The only events doc I found for Craft 3 is the plugin updating guide: https://docs.craftcms.com/v3/extend/updating-plugins.html#events.

Did I miss anything? Appreciate if someone can post a link here.

Also, for Craft 2 events, we used to be able to do $event->params[$paramName] to get the params passed into the events, but I struggle to find a way to do similar things in Craft 3. Any suggestions?

6

Here's a list of Event classes and the "Public Properties" that you can get or set:

https://docs.craftcms.com/api/v3/craft-events-assetevent.html

An example of getting event data:

Event::on(
    Users::class,
    Users::EVENT_BEFORE_ACTIVATE_USER,
    function (UserEvent $event) {
        $userElement = $event->user;
    }
);

Class reference: https://docs.craftcms.com/api/v3/craft-events-userevent.html

An example of setting event data:

Event::on(
    Fields::class,
    Fields::EVENT_REGISTER_FIELD_TYPES,
    function (RegisterComponentTypesEvent $event) {
        $event->types[] = UserState::class;
    }
);

Class reference: https://docs.craftcms.com/api/v3/craft-events-registercomponenttypesevent.html

7

Whilst Doug's answer is useful for knowing the ins and outs of a particular event once you've found it, actually finding which events are available in Craft 3 in the current docs is not straight-forward. After a bit of digging, you'll find that most events are part of Craft's services - so head to the Class Reference and choose the most relevant service from the craft/services menu. The events available to each service are listed at the end. For example: https://docs.craftcms.com/api/v3/craft-services-users.html#events

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.