uasort(): Argument #1 ($array) must be of type array

Created on 22 May 2024, 7 months ago
Updated 6 June 2024, 6 months ago

Problem/Motivation

When updating leaflet module and the civicrm_entity_leaflet to latest versions, and viewing an existing map view settings.
There is an error when trying to save or update any of the view display settings.

2024/05/22 12:33:01 [error] 1995417#1995417: *1363109 FastCGI sent in stderr: "PHP message: Uncaught PHP Exception TypeError: "uasort(): Argument #1 ($array) must be of type array, null given" at /var/www/html/x/drupal10/web/modules/contrib/civicrm_entity_leaflet-civicrm_entity_leaflet/src/Plugin/views/style/CivicrmEntityAddressLeafletMap.php line 702" while reading response header from upstream, client: 195.188.223.90, server: x, request: "POST /admin/structure/views/view/hive_directory/preview/block_2?_wrapper_format=drupal_ajax HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.1-fpm.sock:", host: "x", referrer: "x/admin/structure/views/view/x/edit/block_2"
2

This seems very similar to an issue that existed for leaflet and upgrading versions there
https://www.drupal.org/project/leaflet/issues/3375293 πŸ’¬ TypeError: uasort(): Argument #1 ($array) must be of type array, null given in uasort() (line 1218 of modules/contrib/leaflet/modules/leaflet_views/src/Plugin/views/style/LeafletMap.php). Fixed

Steps to reproduce

Set up a basic contact search view with contextual filter to URL and relationship to address.
Limit results to 1
View everything works as expected.

Update modules to latest
leaflet 10.2.x-dev
civicrm_entity_leaflet 2.0.x-dev
civicrm_entity 4.0.x-dev (unsure if this impacts things)

View the page where the map is displayed or try to modify the configuration

Proposed resolution

Add the check mentioned on the leaflet issue

      // Order the data features based on the 'weight' element.
      if ($features_group && count($features_group) > 1) {
        // Order the data features groups based on the 'weight' element.
        uasort($features_group, [
          'Drupal\Component\Utility\SortArray',
          'sortByWeightElement',
        ]);
      }

Remaining tasks

Raising the MR from gitlab shortly.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024