Answers for "aftersave revision in craft cms"

0

aftersave revision in craft cms

Event::on(
    \craft\services\Elements::class,
    \craft\services\Elements::EVENT_AFTER_SAVE_ELEMENT,
    function (\craft\events\ElementEvent $event) {
        $element = $event->element;
        if(
            $element instanceof \craft\elements\Entry // is entry
            && $element->getSection()->handle == 'pages' // is in 'pages' section
            && !$element->getIsRevision() // is not revision
            && !$element->getIsDraft() // is not draft
            // && !$element->propagating // not during propagating (avoid batch propagating)
            // && !$element->resaving // not during resaving (avoid batch resaving)
        ) {
            // --------------- My Stuff -------------- //
            // $entry is the $element
            // $isNew = $event->isNew
            // ...
        }
    }
);
Posted by: Guest on June-02-2021

Browse Popular Code Answers by Language