0

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)

12
  • Welcome to JSE. While you wait for support, please take our tour. Also, a couple of non-resolving tips: 1. implode('/',explode('.',$query['task'])) is better written as str_replace('.', '/', $query['task']) and 2. If $segments[0] will always have a colon, you can more directly use strstr($segments[0], ':', true) to get the id without generating a temporary array.
    – mickmackusa
    Apr 24 '20 at 15:06
  • Could you put your browser devtools on, trace through the http requests/responses for going from the agendas page to the agenda page, then the effects of logging in and logging out. It would be helpful to have each URL, http request type (get/post) and parameters and response codes – could you add that information to your question? Also could you put the Joomla debug on and have a look in the debug session area when you're doing that navigation, and let us know if there's any differences there for your agenda component. Thanks Apr 24 '20 at 18:38
  • If you're changing the language via the Joomla language switcher module, then at the level you're talking about I think you'd need to have the agenda component supporting Joomla language associations, and have an association set up between the agenda item in one language and the corresponding agenda item in the other language. Plus you'd need the agenda component to use those associations via code in the agenda component's site helpers/association.php file. Is that all in place? Apr 24 '20 at 18:41
  • @RobbieJackson I added the request/reponses. But I am not sure what to add from the Joomla debug page? Also, the helpers/association.php file is not present, but I am more concerned about the login.
    – jansen
    Apr 24 '20 at 22:44
  • OK thanks. Where you've got the POST requests which have the 303 status response, in the response header you'll have the location of the URL which it's redirecting to. Could you add in that URL for those 303 responses? Also looking at the code for user login in components/com_users/controllers/user.php, it sets "the return URL in the user state to allow modification by plugins". Is there any plugin associated with the component (or more generally on your site) which might be modifying this return URL? Apr 25 '20 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.