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.

Example

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

<?php
$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]');
        //Title
        $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
        $modx->mail->setHTML(true);
        if (!$modx->mail->send()) {
            $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send an email message: '.$modx->mail->mailer->ErrorInfo);
        }
        $modx->mail->reset();
        break;
}

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.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • eydolan
  • Lefthandmedia
  • Murray Wood
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

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

Learn more