How to get an entry url from EVENT_AFTER_SAVE_ELEMENT callback? In my plugin I am registering a callback for Elements::EVENT_AFTER_SAVE_ELEMENT event. Previously, in Craft2, I could access the URL of the saved entry from the $event parameter passed into the callback, like so: $event-&gt;params['entry']-&gt;getUrl(). 

However I can't figure out how to get a reference to the entry in the Event model in Craft 3. If I var_dump($event) I can see the data I want nested deep inside a private property which I cannot access. 

How do I access the entry data from the event in Craft 3?
Check out the definition of the ElementEvent that you're passed:

class ElementEvent extends Event
{
    // Properties
    // =========================================================================

    /**
     * @var ElementInterface|null The element model associated with the event.
     */
    public $element;

    /**
     * @var bool Whether the element is brand new
     */
    public $isNew = false;
}


So you can access the element (in your case, presumably an Entry) via:

$event-&gt;element


Make sure to check for null, and depending on how you set up the event listener, that the element is of the type of you're looking for.

For instance, if you want only listen to all elements that are saved, you'd do:

    Event::on(
        Elements::class,
        Elements::EVENT_AFTER_SAVE_ELEMENT,
        function (ElementEvent $event) {
            Craft::debug(
                'Elements::EVENT_AFTER_SAVE_ELEMENT',
                __METHOD__
            );
        }
    );


...but if you only care about Entry elements, you'd do:

    Event::on(
        Entry::class,
        Entry::EVENT_AFTER_SAVE,
        function (ModelEvent $event) {
            Craft::debug(
                'Entry::EVENT_AFTER_SAVE',
                __METHOD__
            );
        }
    );