We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    Anyone else wishing MODX had a few more events to tie into? Specifically I'm thinking how useful it could be if you could respond to a Chunk or Snippet not being found or have a file-based group of System Settings that could be looked up if the regular old System Settings came up blank... a "onBeforeChunkNotFound" event could help message the user that their chunk was not named correctly or it could check against chunks stored on the file system. Anyone else wish there were a few more events like this? Or is there already some way to tie into this?
      • 3749
      • 24,544 Posts
      I assume you mean when processing tags (you can already check in code to see if an object exists).

      It would definitely be handy. I don't think it would slow down page-loads much since I suspect that there's already a test to see if the object was found and the System Event code would only execute when that test failed.

      If you want to play around with it, you could try creating the Event and adding something like this at line 538 of the modParser class file (just above the return $element line):

      if (!$element) {
          $modx->invokeEvent('OnElementNotFound',
              array(
                 'name' = $realname,
                 'class' = $class,
              ),
          ));
      }

      I think it could also be in an else() statement in the test just above there, which would be a little faster.

      A plugin tied to the event could decide (maybe based on a System Setting) which classes to respond to.

      There's code in MyComponent for creating new System Events:

      $newEvents = array (
                      0 =>  array (
                        'name' => 'OnElementNotFound',
                        'service' => 1,
                        'groupname' => 'Whatever', // or ''
                      ),
                  );
      
      
      foreach($newEvents as $k => $fields) {
      
                      $event = $modx->getObject('modEvent', array('name' => $fields['name']));
                      if (!$event) {
                          $event = $modx->newObject('modEvent');
                          if ($event) {
                              $event->fromArray($fields, "", true, true);
                              $event->save();
                          }
                      }
                  }
      [ed. note: BobRay last edited this post 13 years, 2 months ago.]
        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
        • 3749
        • 24,544 Posts
        Just a thought, another way to go would be to write a snippet or plugin that called the modParser class (or a modified version of it) and responded to failures. You could leave out the searches of the cache since a misspelled object definitely wouldn't be in the cache. [ed. note: BobRay last edited this post 13 years, 2 months ago.]
          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
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          Ha. Someone beat us to it: http://tracker.modx.com/issues/9565
            • 3749
            • 24,544 Posts
            But you could still do the pull request. wink
              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