We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I’m wondering about the example code in the two examples here: http://svn.modxcms.com/docs/display/revolution/Plugins

    In the first example, isn’t
    return $output;
    unnecessary (and potentially confusing)?
    Should it maybe be return; or return ’’; ?


    Shouldn’t line 5 in the second example be:
    if (!empty($errorPage)) { 
    ??

    Let me know if these need correcting and what they should be and I’ll fix them.
      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
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: BobRay at Aug 29, 2009, 03:03 PM

      I’m wondering about the example code in the two examples here: http://svn.modxcms.com/docs/display/revolution/Plugins

      In the first example, isn’t
      return $output;
      unnecessary (and potentially confusing)?
      Should it maybe be return; or return ’’; ?
      You are correct, you don’t need to return anything, though a blank string is fine.

      Quote from: BobRay at Aug 29, 2009, 03:03 PM

      Shouldn’t line 5 in the second example be:
      if (!empty($errorPage)) { 
      ??
      I don’t think so; it’s saying if no $errorPage is defined or it has an empty value to show the MODx error page, otherwise send an email and redirect to the defined page.

      I would also suggest the following changes to start with...

      * If the plugin is only intended to operate on a single event, there is no reason for the switch statement at all. This is unnecessary overhead.

      * Creating a reference to $e = &$modx->Event is unnecessary and the uppercase $modx->Event is deprecated. It should be $modx->event and the switch statement, if necessary in more complex plugins intended to be registered on multiple events, could simply be
      switch ($modx->event->name) {



      Then I’ll work on some additions to this, like a new example plugin that is intended to be registered on multiple events, as well as an example to demonstrate using return values, generating output, stopping propagation of the event to additional registered plugins, etc.
        • 3749
        • 24,544 Posts
        Quote from: OpenGeek at Aug 30, 2009, 06:03 PM

        Quote from: BobRay at Aug 29, 2009, 03:03 PM

        Shouldn’t line 5 in the second example be:
        if (!empty($errorPage)) { 
        ??
        I don’t think so; it’s saying if no $errorPage is defined or it has an empty value to show the MODx error page, otherwise send an email and redirect to the defined page.

        Ah ... I thought sendErrorPage() used the defined error page. I see it doesn’t.

        I made a few changes, and added a small example with a case statement. I also added a link to the Wiki System Events page. If the event list is different for Revolution, I’d suggest just adding any new events and putting (Revolution) after them and (Removed in Revolution) next to any that are gone.

        I removed the $output = ""; initializer since we’re setting $output = &$modx->resource->_output in the next line. Let me know if there’s some PHP quirk I’m not aware of that makes it a good idea to initialize it as empty.

        A good example to add might be a plugin that does some filtering or formatting, but in the back end when the doc is saved (maybe one that undoes & in snippet tags). wink

        The captcha plugin (or some version of it) also might be a good example to add because it listens to two separate events and returns a value.

          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
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: BobRay at Aug 31, 2009, 12:18 AM

          I removed the $output = ""; initializer since we’re setting $output = &$modx->resource->_output in the next line. Let me know if there’s some PHP quirk I’m not aware of that makes it a good idea to initialize it as empty.
          There really is no need for the $output variable at all IMO; it’s another unnecessary reference created simply because folks are lazy about typing the full variable’s name.
            • 3749
            • 24,544 Posts
            Quote from: OpenGeek at Aug 31, 2009, 09:01 AM

            Quote from: BobRay at Aug 31, 2009, 12:18 AM

            I removed the $output = ""; initializer since we’re setting $output = &$modx->resource->_output in the next line. Let me know if there’s some PHP quirk I’m not aware of that makes it a good idea to initialize it as empty.
            There really is no need for the $output variable at all IMO; it’s another unnecessary reference created simply because folks are lazy about typing the full variable’s name.

            That would include me. 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