We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    Is it possible to create a top-level menu item that will redirect the user to the resource/update page, with the resource id being calculated based on the user?

      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 don't think there's an easy way to do that. You can definitely have a Top Menu item that sends them to the Create/Edit resource page, but the parameters would have to be dynamic, and I don't think any tag you put there would be interpreted.

      You might be able to create a plugin connected to OnBeforeManagerPageInit that checked the action (available as $action in the plugin), and if it was resource/create or resource/update redirected based on $modx->user (if that's set -- I think it would be).

      I think it would work with 2.2 or 2.3, but not both unless you had code to detect the version and act accordingly.

      It would be cool if it worked to have an "Edit Your Page" Top Menu item.

      For starters, I would create a chunk named 'Debug' and create a plugin attached to OnManagerPageInit with this code:

      $chunk = $modx->getObject('modChunk', array('name' => 'Debug'));
      if ($chunk) {
          $content = $chunk->getContent();
          $msg = "\nUser: " . $modx->user . "\nAction: " . print_r($action, true);
          $chunk->setContent($content . $msg);
          $chunk->save();
      }
      


      Visit the Create/Edit Resource page and QuickEdit the Debug chunk to see what you get.

      [ed. note: BobRay last edited this post 12 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
        I just tried it and 'resource/update' was in $actions['controller'], but no user (I tried both $modx->user and $user).

        Still, you could set the user's ID or username in a $_SESSION variable in a plugin attached to one of the Manager Login 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
          • 3749
          • 24,544 Posts
          Aha. I dumped $modx->config into the chunk and found it.

          The action (at least in 2.3.1) is in $actions['controller'] and the username is in $modx->config['username']. No user ID that I could find, though, so you'd have to get that in order to generate the URL.

          BTW, be *very* careful putting code in a plugin attached to OnManagerPageInit. Any syntax error will break the Manager completely and you'll have to edit or disable the plugin in PhpMyAdmin before you can use the Manager again.

          Quick method to get user ID from username:

          $username = $modx->config['username'];
          $query = $modx->newQuery('modUser', array(
              'username' => $username,
          ));
          $query->select('id');
          $userId = $modx->getValue($query->prepare());
            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
            My users will have their assigned resource ID in an extended field. But if I can't use any kind of code, it has to be pure Javascript, then a window.location isn't going to work.

            I have the user blocked from viewing the "welcome" dashboard. If he clicks on the icon to the left, he gets a blank page with "permission denied", which isn't very nice. So I think I'll create a custom dashboard for these users, with a nice "Edit Your Page" button. That I can do! Then if he tries to do something sneaky with his URLs and ends up somewhere forbidden, he'll at least be able to get back to his page.
              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 not sure what you mean by "I can't use any kind of code."

              Once you have the user ID and the action, you should be able to get the resource ID, generate a URL, and use $modx->sendRedirect() in the plugin.

              That would go something like this:

              $action = $actions['controller'];
              if ($action != 'resource/create' && $action != 'resource/update') {
                  return '';
              }
              username = $modx->config['username'];
              $query = $modx->newQuery('modUser', array(
                  'username' => $username,
              ));
              $query->select('id');
              $userId = $modx->getValue($query->prepare());
              
              $profile = $modx->getObject('modUserProfile', array('internalKey' => $userId));
              $resourceId = null;
              if ($profile) {
                 $extended = $profile->get('extended');
                 $resourceId = $extended['resourceId']; // change resourceId to whatever it is
              }
              
              if ($resourceId) {
                 /* Generate Manager URL here */
                 $url = MODX_MANAGER_URL . 'a=' . $action . '&id=' . $resourceId;
                 $modx->sendRedirect($url, "", "", "full");
              
              }
              return '';
              




                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
                BTW, if NewsPublisher would handle the pages, it would be really easy to create a snippet to just show the edit button on their own pages (createdby == userId) in the front end. That would launch NewsPublisher for their page.
                  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
                  I know. But we need TVs, and MIGx TVs at that.
                    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 figured. Have you tried NewsPublisher with a MIGx TV? I think it would treat it as a text TV, but I'm not sure what you'd get.
                      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
                      No, I didn't actually try it. You mentioned to me that you didn't think it would work too well, since so much of it depends on the extJS in the Manager. And while it is possible to load all that up and use it in the front-end, I really, really don't want to go there.
                        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