I'm using modX Revo with plugins Login and Babel. As there was wrote at Babel manual I made 2 contexts for two languages, used TV params and wrote contextSwitch plugin. It is mostly like plugin from example at the manual. After that I put plugin on event HandleRequest.
Everything is working except switching context after login: if user is authorized, modX shows only main page, the others show 404 page. I tried to rummage in the code and found out that method switchContext of model modx (line 1843 of /core/model/modx/modx.class.php) returns false.
public function switchContext($contextKey, $reload = false) {
$switched= false;
if ($this->context->key != $contextKey) {
$switched= $this->_initContext($contextKey, $reload); // RETURNS FALSE
if ($switched) {
if (is_array($this->config)) {
$this->setPlaceholders($this->config, '+');
}
}
}
return $switched;
}
It happens, because context can't be initiated (method _initContext of the same class at the same file). Here context is correctly creating, when we ask to switch to it, but $this->context->checkPolicy('load') returns false (near 2169 line of the same file).
protected function _initContext($contextKey, $regenerate = false) {
// HERE IS EVERYTHING ALLRIGHT
$initialized= false;
$oldContext = is_object($this->context) ? $this->context->get('key') : '';
if (isset($this->contexts[$contextKey])) {
$this->context= & $this->contexts[$contextKey];
} else {
$this->context= $this->newObject('modContext');
$this->context->_fields['key']= $contextKey;
}
if ($this->context) { //HERE TRUE
if (!$this->context->prepare((boolean) $regenerate)) { // HERE TRUE
$this->log(modX::LOG_LEVEL_ERROR, 'Could not prepare context: ' . $contextKey);
} else {
if ($this->context->checkPolicy('load')) { // HERE FALSE - MODX CAN'T DO IT
// .. SOME OTHER modX CODE
So after that I stopped to rummage at the core. May be somebody already saw something like that or know modx Revo core good to answer why modx can't switch context when user is logged in?
P.s. I tried to use another event for context switch plugin - but of course this event is the most correct for the plugin. And I'm accenting that modx can't switch context only while user is logged in!
UPDATE
I tried to edit some permissions. But nothing has happend (I cleared cash and relogged all users). Here is screeshot of context permissions (sorry for nonEnglish, however it should be clear):
UPDATE 2 Permissions were wrong: they have to be all 9999 and "list, veiw, load". But the same time I can't log in while i'm at second context as before I couldn't. Now I tried to find out is it the same problem or not.
UPDATE 3
The second problem with login is solvineg very easy: in snippet params there should be &contexts=web,eng
but $this->context->checkPolicy('load') returns false (near 2169 line of the same file).
Well, there's your answer! The user needs at least "load" permission for the context in order to switch to it.
Go to Security > Access Policies > right click the user group and choose to update it. In the Context Access tab make sure all front-end facing contexts are listed there with preferably the "Load, List & View" access policy. May want to do that for the Administrator user group first to prevent getting locked out of it yourself, as well as the (anonymous) group which is used for not logged in users.
I think, though not 100% sure without seeing more about your specific setup, you didn't gave the user group access to the second context which would explain why it does work for anonymous users.