We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    Is there documentation somewhere on using system events in snippets?
      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
      • 40706
      • 128 Posts
      As fasr as i know only a few Snippets are using System Events the only one I have ever seen this was the Login Package. Inside the user creation and activation there are calls like that:

      /* invoke OnUserActivate event */
              $this->modx->invokeEvent('OnUserActivate',array(
                  'user' => &$this->user,
              ));


      Think its self explaining for an extra developer...
      The Main Problem would be always to know what events there are. Then go to http://rtfm.modx.com/display/revolution20/System+Events look for it and see what parameters are required.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Thanks; I was just wondering if maybe there were any restrictions or special handling required for invoking any of the events. I have in mind modifying the Gallery upload functionality to invoke the OnFileManagerUpload event so that there can be a plugin to do custom image manipulation on upload, but it's not using the file manager so I'm not sure if it can be invoked by a snippet.

        Perhaps it would be better to have its own event, and register it on installation? I knew how to do that with Evo (WebLoginPE did that), but not with Revo.
          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
          • 22303 MODX Staff
          • 10,725 Posts
          You can certainly create a custom modEvent object, package it, and provide a resolver to register it on various events. You can even use the install options to make registration optional, perhaps even per event. Adding a vehicle for your custom modEvent object in your build script is easy enough:

          $myEvent = $modx->newObject('modEvent');
          $myEvent->set('name', 'MyEvent');
          $attributes = array(
              xPDOTransport::UNIQUE_KEY => 'name',
              xPDOTransport::UPDATE_OBJECT => true
          );
          $vehicle = $builder->createVehicle($myEvent, $attributes);
          $builder->putVehicle($vehicle);
          


          Then you can add your modPlugin and a resolver for resolving the plugin events for your custom Event (or core Events for that matter). You can see an example of this done with core events in the transport build scripts for various components. The DBAPI plugin I made for Revo has one such example.
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Thank you! That's a bit rich for me to digest right now, but I'm sure if I look at it for a few days (or weeks or months...) I'll figure it out. I'm still trying to figure out how to package up a template with MyComponent. Well, and how to use PhpStorm properly as well.
              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
              • 3749
              • 24,544 Posts
              If you're using MyComponent 3.0, it will create the new System Event(s) for you.
                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