We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37521 ☆ A M B ☆
    • 30 Posts
    What is the best way to know opened manager page in events OnManagerPageBeforeRender and OnManagerPageInit?
    I've found that $controller->config has ID of action but some pages have different id's at different sites.

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

    [ed. note: argnist last edited this post 13 years, 7 months ago.]
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      It would be nice if you could edit your first post, and set the topic to something more concise, like Opened Manager Page, then put the rest of that long string into a more descriptive question.
        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
        • 37521 ☆ A M B ☆
        • 30 Posts
        Oops smiley Modified.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You should be able to use $_GET or perhaps $_REQUEST to determine just what was being done.
            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
            I'm pretty sure there's a way to get the name of a manager action based on its ID (and vice versa). Mark Hamstra told me how to do it, but I can't remember what it is. I sent him a tweet, so hopefully he'll chime in and we'll all know. 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
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              You can get the action, but not necessarily the resource/element being loaded for modification. For example, to open a plugin for editing you'll get something like
              http://domain.com/manager/index.php?a=13&id=4


              I still haven't been able to figure out the actual path the Manager takes to process this. Evo was easy; all the actions were listed in the manager's index.php file in one big switch statement, and simply included the appropriate files from manager/actions/. [ed. note: sottwell last edited this post 13 years, 7 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
                • 37521 ☆ A M B ☆
                • 30 Posts
                Quote from: BobRay at Feb 21, 2013, 02:47 AM
                I'm pretty sure there's a way to get the name of a manager action based on its ID (and vice versa). Mark Hamstra told me how to do it, but I can't remember what it is. I sent him a tweet, so hopefully he'll chime in and we'll all know. wink
                I think I understood that I can check $controller->config['controller'] or get it by $modx->getObject('modAction', $actionId) and if it is needed to me then do with this page anything. But interesting what Mark will answer then.
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  It's in the database in the modx_actions table, and gets cached (if its caching is enabled in the system settings) in the core/cache/action_map/mgr/actions.cache.php file. For example;
                    10 => 
                    array (
                      'id' => '10',
                      'namespace' => 'core',
                      'controller' => 'element/chunk/update',
                      'haslayout' => '1',
                      'lang_topics' => 'chunk,category,propertyset,element',
                      'assets' => '',
                      'help_url' => 'Chunks',
                      'namespace_name' => 'core',
                      'namespace_path' => '/Users/sottwell/Desktop/Working/htdocs/revo226/manager/',
                      'namespace_assets_path' => '{assets_path}',
                    ),
                  

                  So all of this should be available in the controller array. However, this won't tell you which chunk is being edited; you'd have to get that from the GET, I think.
                    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
                  • discuss.answer
                    • 18373 ☆ A M B ☆
                    • 3,141 Posts
                    You can reference the $modx->actions or in javascript MODx.actions array to see what the action is.

                    PHP Example:
                    if (array_key_exists($_GET['a'], $modx->actions)) {
                      // Only do something on resource/update
                      if ($modx->actions[$_GET['a']] == 'resource/update') {
                        $modx->regClientStartupScript('foo/bar.js');
                      }
                    }
                    


                    Keep in mind that in 2.3 the modAction object has been mostly deprecated (it is being kept for backwards compatibility so you can still use Extras relying on it, but the core no longer uses it), and instead the action is being put into the URL. This is already available for testing in the develop branch on github.

                    So manager urls go from:
                    manager/index.php?a=13&id=34
                    to:
                    manager/index.php?a=resource/update&id=34
                    or for extras that use the 2.3 style:
                    manager/index.php?a=listing/update&namespace=mynamespace&id=34
                    or for extras that are using 2.2 compatible style it is the same:
                    manager/index.php?a=78&id=34

                    Reason I'm adding this here, is because as of 2.3, the $modx->actions array will be mostly empty - only 3rd party actions that have not been updated specifically for 2.3 will be available in that array. Your core checks would end up similar to this:
                    if ($_GET['a'] == 'resource/update') {
                       //foo bar!
                    }
                      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.