I inherited a site with a custom component: an agenda viewer. When I click on an agenda-item from the list and then login (via login module) or change the language, I am not redirected to the agenda item but instead to the agenda list again.
How an I fix this so that I am being redirected to the agenda-item page again?
Logging out works perfectly however.
The base64 return value is also the correct url for the agendaitem page (for both login and logout).
Based on previous searches, I know that this has to do something with SEF. And when I disable SEF, the custom component page cannot be found (and I would like to keep SEF enabled). Also based on previous research, I think the issue must lie in router.php
.
Here is that file:
<?php
// No direct access
defined('_JEXEC') or die;
/**
* @param array A named array
* @return array
*/
function Protagoras_agendaBuildRoute(&$query)
{
$segments = array();
if (isset($query['task'])) {
$segments[] = implode('/',explode('.',$query['task']));
unset($query['task']);
}
if (isset($query['id'])) {
$segments[] = $query['id'];
unset($query['id']);
}
return $segments;
}
/**
* @param array A named array
* @param array
*
* Formats:
*
* index.php?/protagoras_agenda/task/id/Itemid
*
* index.php?/protagoras_agenda/id/Itemid
*/
function Protagoras_agendaParseRoute($segments)
{
$vars = array();
/**
* Agenda-item
*/
if(!empty($segments[0])) {
$id = explode( ':', $segments[0] );
$vars['id'] = $id[0];
$vars['view'] = 'agendaitem';
} else {
$vars['view'] = 'agendaitems';
}
return $vars;
}
?>
Edit: added http requests/responses
While not logged in:
Navigating to agenda:
https://www.protagoras.tue.nl/studenten/vereniging/agenda
Navigating to agenda item:
https://www.protagoras.tue.nl/studenten/vereniging/agenda/1760-woensdag-puzzeldag
Logging in while on agenda item page:
status 303 Post:
https://www.protagoras.tue.nl/studenten/vereniging/agenda
form data:
username=USERNAME
password=PASSWORD
option=com_users
task=user.login
return=aHR0cHM6Ly93d3cucHJvdGFnb3Jhcy50dWUubmwvc3R1ZGVudGVuL3ZlcmVuaWdpbmcvYWdlbmRhLzE3NjAtd29lbnNkYWctcHV6emVsZGFn
85abb6f5daccba2a45c3c4ff59f8cfe7=1
Submit=""
status 200 Get:
https://www.protagoras.tue.nl/studenten/vereniging/agenda
Logging out while on agenda item:
status 303 Post:
https://www.protagoras.tue.nl/studenten/vereniging/agenda
form data:
option=com_users
task=user.logout
return=aHR0cHM6Ly93d3cucHJvdGFnb3Jhcy50dWUubmwvc3R1ZGVudGVuL3ZlcmVuaWdpbmcvYWdlbmRhLzE3NjAtd29lbnNkYWctcHV6emVsZGFn
0714e4c8ac53d16d7ec8287fe4eedb9f=1
status 200 Get:
https://www.protagoras.tue.nl/studenten/vereniging/agenda/1760-woensdag-puzzeldag
Edit 2: added Post request locations
response header location Post request when logging in:
Location: /studenten/vereniging/agenda
response header location Post request when logging out:
Location: https://www.protagoras.tue.nl/studenten/vereniging/agenda/1760-woensdag-puzzeldag
SOLUTION: component did not contain associations (https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_Associations). Disabling plugins->languagefilter->associations did the trick but it would be best to write an associations functionality for this component. Thanks Robbie Jackson (see comments below)
implode('/',explode('.',$query['task']))
is better written asstr_replace('.', '/', $query['task'])
and 2. If$segments[0]
will always have a colon, you can more directly usestrstr($segments[0], ':', true)
to get the id without generating a temporary array. – mickmackusa♦ Apr 24 '20 at 15:06