onAfterSave

The onAfterSave handlers gets fired after any piece of LiveWhale content gets saved, including shared/linked copies or items getting restored from the trash.

This covers both the create and update cases. If you want to logically separate your custom module code to cover just one of those cases, use onAfterCreate or onAfterUpdate. To take action only after public submissions, use onAfterPublicSubmission.

Note that in some cases—a Linked Calendar refreshing hundreds of events, an import script running, or a repeating event series being saved—this handler can be run many times in a row.

In most cases, you can use $_LW->save_data[‘variable’] to access values from the most recently saved item. Here’s an example that checks $_LW->save_data[‘gid’] and sends a custom email notification when items from a certain group are created or updated.

<?php
    $_LW->REGISTERED_APPS['my_app']=[
       'title'=>'My App',
       'handlers'=>['onAfterSave'],
    ];

    class LiveWhaleApplicationMyApp {

      public function onAfterSave($type, $id) { 
        global $_LW;

        if ($_LW->save_data['gid'] == 123) { // if saved item was in specific group

            // send custom email notification
            $email = 'registrar@myschool.edu';
            $subject = 'Item added or updated;
            $message = "An item in the Registrar group was saved: ' . $_LW->getPermalinkUrl($type, $id);
            $_LW->d_messages->sendMail($to, $subject, $message);
            
        }

      }

   }
?>