Jump to main content Jump to doc navigation

Event: OnDocFormDelete

Fires after a Resource is deleted via the manager.

  • Service: 1 - Parser Service Events
  • Group: Documents

Event Parameters

Name Description
resource A reference to the modResource object.
id The ID of the Resource.
children An array of IDs of children of this resource which were deleted.


Such a plugin will send a list of deleted resources by email:

$eventName = $modx->event->name;
switch($eventName) {
    case 'OnDocFormDelete':
        $modx->getService('mail', 'mail.modPHPMailer');
        $modx->mail->set(modMail::MAIL_FROM, $modx->getOption('emailsender'));
        $modx->mail->set(modMail::MAIL_FROM_NAME, $modx->getOption('site_name'));
        //Address of the recipient
        $modx->mail->address('to', '[email protected]');
        $modx->mail->set(modMail::MAIL_SUBJECT, 'Resources have been removed');
        // Body of letter
        foreach ($children as $value) {
            $resource = $modx->getObject('modResource', $value);
            $name .= '<br>'.$resource->get('pagetitle');
        $contentbody = 'The resource was removed from id '.$id.' and with him '.$name;
        $modx->mail->set(modMail::MAIL_BODY, $contentbody);
        // We send
        if (!$modx->mail->send()) {
            $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send an email message: '.$modx->mail->mailer->ErrorInfo);

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.



$0 per month—let's make that $500!

Learn more