We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36695
    • 47 Posts
    I have a plugin that fires OnManagerLogin. In the plugin's code I am trying to get a modContext object, but it fails with a message along the lines of "Principal 0 does not have permission to load object of class modContext with primary key: mycontextkey".
    I've debugged through to this error message and it looks like the $user var sent to the event is indeed the user that just logged in, but $modx->user is still anonymous (hence the "Principal 0" in the error message).
    I'm trying to access the context like this:
    $ctx = $modx->getContext('mycontextkey);
    

    I'm pretty sure it's not an ACL issue, as I have got around the problem by using the OnManagerPageInit event. At this point the code above does work, and I can get the context I want. I'm currently just setting a session var when my logic is complete and then checking for that before running it to prevent doing it on every page load (I only need it once per session).
    Is this possibly part of the bugs alluded to in these posts: https://forums.modx.com/index.php?topic=61831.0 or https://forums.modx.com/thread/?thread=28559&page=1, or am I missing something about the order of events?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      The OnManagerLogin event provides a "loginContext" value that you should be able to use.

      http://rtfm.modx.com/display/revolution20/OnManagerLogin
        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
        • 36695
        • 47 Posts
        Thanks Susan. However, it's not the current context that I want to get (sorry, should have been clearer). Also, the value of loginContext is just the name(key) of the current context rather than the object itself.
        However, the addContexts variable looks intriguing - how do I get other contexts in here?