We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39653
    • 13 Posts
    I'm playing around with plugins, trying to figure out the ins and outs of their execution, etc.

    To start, I have my plugin with the following code:

    return $modx->event->name;
    


    According to the documentation, the return statement should write the text to the error log.

    This works great when I only have two system events checked:

    OnWebPageComplete
    OnWebPagePrerender

    As soon as I add in OnParseDocument to the list of system events to listen for, the whole site produces a 500 http error.

    I'm using MODx v2.2.5, I've got two pages to the site, with 1 template. Theat template loads several system settings(site name, site URL), and a buch of document data(page title, content, summary). There is a bit of content on the page, about a paragraph or two, just for show.

    Any thoughts on what would cause the site to basically implode with the OnParseDocument system event?

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Can you post the entire plugin code?
        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
        • 39653
        • 13 Posts
        Quote from: sottwell at Nov 27, 2012, 02:12 AM
        Can you post the entire plugin code?

        The code listed in the first post is the entire plugin code.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You have three events selected for that plugin, if I understand correctly. You should have a switch to deal with each event individually if you have more than one event for a plugin. For example, the plugin that is installed with Gallery:
          switch ($modx->event->name) {
              case 'OnTVInputRenderList':
                  $modx->event->output($corePath.'elements/tv/input/');
                  break;
              case 'OnTVOutputRenderList':
                  $modx->event->output($corePath.'elements/tv/output/');
                  break;
              case 'OnTVInputPropertiesList':
                  $modx->event->output($corePath.'elements/tv/inputoptions/');
                  break;
              case 'OnTVOutputRenderPropertiesList':
                  $modx->event->output($corePath.'elements/tv/properties/');
                  break;
          ...
          
            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
            • 39653
            • 13 Posts
            Quote from: sottwell at Nov 27, 2012, 10:28 AM
            You have three events selected for that plugin, if I understand correctly. You should have a switch to deal with each event individually if you have more than one event for a plugin.

            Correct, I should have a switch statement if I have more than 1, but there isn't any functionality right now in my plugin that cares what event was triggered.

            Even so, adding this in produces the same result. Everything work fine until I check OnParseDocument in the System Events area:

            $eventName = $modx->event->name;
            switch($eventName) {
                case 'OnWebPagePrerender':
                	return $eventName;
                    break;
                case 'OnWebPageComplete':
                	return $eventName;
                    break;
                case 'OnParseDocument':
                	return $eventName;
                    break;
            }
            

              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Odd. With OnParseDocument
              echo "<pre>";
              print_r($modx->event);
              echo "</pre>";
              exit();

              does work; the page outputs a display of the event object.
              But trying to return anything kills it.
                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
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                I think I may have an idea... the event array contains the content of the template, including the [[*content]] tags. Could this somehow be causing a loop, repeatedly trying to parse the content until it forces the 500 error? The other two events don't have that value.
                modSystemEvent Object
                (
                    [name] => OnParseDocument
                    [activePlugin] => Testing
                    [propertySet] => 
                    [_propagate:protected] => 1
                    [_output] => 
                    [activated] => 1
                    [returnedValues] => 
                    [params] => Array
                        (
                            [content] => 
                
                
                
                
                
                [[Wayfinder? &startId=`0`]]
                [[*content]]
                
                
                        )
                
                )
                [ed. note: sottwell last edited this post 13 years, 10 months ago.]
                  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
                  • 39653
                  • 13 Posts
                  I modified your code a bit:

                  if($modx->context->key != "mgr") {
                  echo "<pre>";
                  print_r($modx->event);
                  echo "</pre>";
                  exit();
                  }


                  I also created a blank template, and I still get a 500 error roughly half the time I load the page. I'm not sure if that is a plugin issue, or a server issue. With the plugin disabled, I don't get any 500 errors.
                    • 3749
                    • 24,544 Posts
                    You generally don't want to return anything from a plugin unless you know what MODX is expecting. MODX ignores the return value from the three events you're using, but it's possible that returning anything is causing a problem.

                    It's also a questionable practice to have plugins generate output because it often crashes things.

                      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
                      How does one go about displaying what is available, for example displaying the SESSION array, or what values are being made available by the event?
                        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