We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42645
    • 1 Posts
    Is there a way from a plugin to trigger an event (say, "OnBeforeDocFormSave") from a plugin? Or to bind to an event, but stop the actual MODx event from happening?

    An example would be binding to the Save event, but prevent MODx from saving the resource.
      • 3749
      • 24,544 Posts
      You can trigger an event with $modx->invokeEvent(), but I would hesitate to do that in a plugin unless you're triggering your own custom event, since you're in the middle of another event -- things could get weird.

      Some events have a return value that can affect subsequent processing, but most don't. OnDocFormSave does not, but OnBeforeDocFormSave does.

      Looking at the code, if your OnBeforeDocFormSave plugin returns false or an array of error messages, the save might be aborted, but I've never tried it.

      In a plugin tied to OnDocFormSave, I don't think there's any way to abort the save, but you could delete the resource that's just been saved.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        A plugin can always abort further processing altogether using the PHP exit() function, but that leaves you looking at an empty right section in the page.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org