Redirection when navigating to modules list, groups list and activities list

Created on 2 January 2025, 4 months ago
Updated 2 February 2025, 2 months ago

Problem/Motivation

I'd been stuck on this issue for days. I recently created a new install of opigno drupal 10 using acquia recipe alongside using lando. The issue that I am running into is whenever I navigate to my groups page ( admin/structure/groups ) it is recursively redirecting to itself which then causes it to throw a 'Too many redirects occurred' error. I didn't add any add any other modules other than the language module and I didn't add any modules that would redirect.

Steps to reproduce

use composer create-project opigno/opigno-composer example-folder

cd into your example-folder

run lando init

choose current working directorty

choose acquia

select your acquia account

and choose your environment

run sed -i'.original' 's/web\//docroot\//g' composer.json

change folder name web to docroot

delete web dir

renamed files from 'web' to 'docroot' in composer.json

added webroot: docroot in lando.yml

ran 'compose dump'

ran 'compose install'

Proposed resolution

The issue lies in the `checkRedirection` method in the `QueryPathEventSubscriber` class.

1. Session Data Conflict:
- The session stores `ajax_page_state`, which is not relevant for redirection but gets checked during subsequent requests.
- The presence of `ajax_page_state` causes a mismatch between current query parameters and the session state, triggering the redirection repeatedly.

2. Recursive Redirection:
- The `RedirectResponse` is continuously generated because the comparison between the current request and the session-stored state does not account for `ajax_page_state`.

here is the revised code.

php
public function checkRedirection(ResponseEvent $event): void {
  $available_routes = [
    'entity.opigno_activity.collection',
    'entity.opigno_module.collection',
    'entity.group.collection',
  ];
  $current_route = $this->routeMatch->getRouteName();
  if (!in_array($current_route, $available_routes)) {
    return;
  }

  $request = $this->requestStack->getCurrentRequest();
  $session = $request->getSession();
  $param = $request->query->all();

  // Exclude ajax_page_state from query parameters.
  unset($param['ajax_page_state']);

  if (!empty($param)) {
    $session->set($current_route, $param);
    return;
  }

  $order_values = $session->get($current_route);

  // Exclude ajax_page_state from session state.
  if (!empty($order_values)) {
    unset($order_values['ajax_page_state']);
  }

  if (!empty($order_values)) {
    // Prevent recursive redirection.
    if ($param == $order_values) {
      return;
    }

    $url = Url::fromRoute($current_route);
    $url->setOption('query', $order_values);
    $response = new RedirectResponse($url->toString());
    $event->setResponse($response);
  }
}

🐛 Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024