TypeError as an array is not returned after redirecting

Created on 14 June 2023, over 1 year ago
Updated 8 September 2023, about 1 year ago

Problem/Motivation

When using this module we are getting a TypeError after the plugin redirects.

TypeError: Drupal\facets\FacetManager\DefaultFacetManager::sortFacetResults(): Argument #2 ($results) must be of type array, null given, called in /app/web/modules/contrib/facets/src/FacetManager/DefaultFacetManager.php on line 350 in Drupal\facets\FacetManager\DefaultFacetManager->sortFacetResults() (line 510 of /app/web/modules/contrib/facets/src/FacetManager/DefaultFacetManager.php)

ActiveByDefaultProcessor breaks the BuildProcessorInterface as it does not return a value and execution continues. This results in $results becoming NULL as the DefaultFacetManager builds the facet.

Steps to reproduce

  1. Enable the module and configure a facet to redirect to the first item
  2. Ensure the facet has at least 1 sort plugin configured
  3. Navigate to the search result
  4. Observe you have been redirect
  5. Observe the error is in the logs

Proposed resolution

Drupal discourages terminating the execution mid-request. We should return the results as is defined by the interface.

While investigating this I found that the redirect is not performed exactly as documented in https://www.drupal.org/node/2023537 β†’

  1. Ensure the session is saved and kernel events are triggered as per "Redirecting when not in context of a controller" under https://www.drupal.org/node/2023537 β†’
  2. return results

Remaining tasks

  • Review
  • Commit

User interface changes

n/a

API changes

n/a

Data model changes

n/a

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡³πŸ‡ΏNew Zealand ericgsmith

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

Comments & Activities

Production build 0.71.5 2024