We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40404
    • 21 Posts
    Is there any way to hook any and all connector responses before they're sent?

    The OnManagerPageAfterRender system event hooks the response of a manager page, but most of the visible contents are returned via the connector(s), so are not caught by that event.

    The solution doesn't have to be an actual system event, but can't hack core.

    This question has been answered by BobRay. See the first response.

      • 3749
      • 24,544 Posts
      The possible events are here.

      OnManagerPagePrerender should give you the page results before they're displayed, but unfortunately, much of the output on a Manager page is generated on the fly by JS code, so there's really no way to capture it on the server side.

      Can you give more details about what you're trying to do and why? There might be another way to approach 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
        • 40404
        • 21 Posts
        Because of the way we integrated MODX with our SSO, the MODX usernames are not human-friendly. Ideally anywhere a username appears in the Manager (except the user management form) it should display the fullname instead.

        Using OnManagerPageAfterRender I have this working for the initial HTTP response, but as you said most of the manager content is delivered "on the fly" via JS through connectors, which I haven't figured out how to hook. I could do it with additional JS that parses the page after the injection, but I'd prefer to keep the load on the server since ExtJS is already heavy.
          • 3749
          • 24,544 Posts
          That's a tough one. What do you get when you dump the content in a plugin attached to OnManagerPageAfterRender to the MODX error log?


          if (isset($controller)) {
              $modx->log(modX::LOG_LEVEL_ERROR, '[' . $modx->event->name . '] ' .  $controller->content);
          }
          return '';



          $controller is a reference variable, so if the username is there in either place, you could use str_replace() on it.

          [Update] - Sorry if I broke your Manager. sad -- I broke mine. The updated code above is safe to use, but should be connected only to OnManagerPageAfterRender.

          If the site is broken, you can go into the modx_site_plugins table and set the 'disabled' field of the plugin to 1. Then delete all files in the core/cache directory before visiting the Manager (you may also have to force a reload of the browser page).
          [ed. note: BobRay last edited this post 10 years, 7 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
            • 40404
            • 21 Posts
            That's exactly what I'm doing, but again, it's only catching the initial page load, not the AJAX content.
            • discuss.answer
              • 3749
              • 24,544 Posts
              I'm seeing the username in the output of the Manager header, but that's already the full name (unless I customized that in the past). As you say, there's no output for the JS-generated stuff like the users grid.

              The only way I can think of to do it would be to put the "bad" username somewhere else, either in an unused user field (remote_key is varchar(255) ), an unused profile field , a profile extended field (I don't recommend this), or a custom table.

              I think remote_key is the best option (and I think it may actually be meant for this purpose).

              The human-readable username can go in the 'username' field.

              Your SSO code would have to be rewritten to use the "bad" username, wherever it is, but you're probably already using a plugin attached to OnManagerLogin and/or OnWebLogin, so just that plugin would have to be modified. Then all the manager pages would be show the human-readable usernames (which could be duplicates of the fullname if necessary).
                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
                • 40404
                • 21 Posts
                Oh dang... I totally missed the remote_key and remote_data fields! That's a perfect fix. Thanks!

                And yes, you must have customized your user menu... the default is to show the username.
                  • 3749
                  • 24,544 Posts
                  I'm glad that will work for you. smiley

                  I just remembered -- in the more recent versions or Revolution, you can just change the manager_use_fullname System Setting to Yes. wink

                  I doubt that it affects anything other than the name in the Manager header.
                    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
                    • 40404
                    • 21 Posts
                    Gah! My MODX-fu is slacking. Time to re-RTFM!!!
                      • 3749
                      • 24,544 Posts
                      I don't think you'll find manager_use_fullname or remote_key there yet (I could be wrong).

                      BWT, there's a handy reference to the MODX object fields here.

                      And one for the MODX System Events.

                        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