Returning a boolean from a uasort comparison function is deprecated in PHP 8 and produces a warning on the group type permissions form. Switching the comparison to use the spaceship operator fixes this.

Symptoms

(for people can find this issue more easily)

Deprecated function: uasort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in Drupal\group\Access\GroupPermissionHandler->sortPermissions() (line 268 of modules/contrib/group/src/Access/GroupPermissionHandler.php).

Issue fork group-3210808

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

davisben created an issue. See original summary.

davisben’s picture

Status: Active » Needs review
StatusFileSize
new1.02 KB

Here is a patch.

tim.anderson’s picture

This may be superseded by https://www.drupal.org/project/group/issues/3254097. That work as committed to 2.0.x, and the issue says it may be backported, but the patch applies cleanly to 1.4. Identical solution though. Thanks for providing this several months ago!

chi’s picture

Status: Needs review » Reviewed & tested by the community

The patch fixed the notice for me.

carroll_webprog’s picture

This patch#2 also worked for me thank you!

pcate’s picture

Patch #2 worked for me as well.

bessonweb’s picture

This patch work good for me too !

dpi’s picture

⬆️

heddn’s picture

+1 on RTBC.

jimmynash’s picture

Patch in #2 works for me as well.

jan-e’s picture

The patch at #2 applied without problems on Group 8.x-1.5

Hunk #1 succeeded at 256 (offset -21 lines).

sachbearbeiter’s picture

+1 on RTBC

scotwith1t’s picture

Another +1 here. Been using this patch in multiple builds in prod for a while :)

austin_brian’s picture

The patch at #2 applied without problems on Group 8.x-1.5

+1 RTBC

shashikanth171 made their first commit to this issue’s fork.

donquixote’s picture

Issue summary: View changes
donquixote’s picture

Patch looks good!

Just for the fun of it, the following would be a shorter version of the compare function and uasort() call:

    uasort($permissions, function (array $permission_a, array $permission_b) use ($modules) {
      return ($modules[$permission_a['provider']] <=> $modules[$permission_b['provider']])
        ?: ($permission_a['section'] <=> $permission_b['section'])
        ?: (strip_tags((string) $permission_a['title']) <=> strip_tags((string) $permission_b['title']));
    });

But let's go ahead with the current patch, anything else could be a follow-up.

Yuri’s picture

Patch #2 makes my views blocks disappear that display group content with some group content relations. Did not dig deep in this yet.
Drupal 9.4.10, PHP8.1.14, Using installation profile social-11.7.0-rc1 that uses Group 8.x-1.5

joe_carvajal’s picture

Patch #2 works perfectly for me with these versions:

- PHP 8.1.18
- Drupal 9.5.9
- Group 8.x-1.5

But reading the docs I decided to move to Group 2.1, as recommended. By the way, the GroupPermissionHandler.php file has the patch applied there.

jan-e’s picture

Status: Reviewed & tested by the community » Fixed

Fixed in Group 8.x-1.6

dpi’s picture

Status: Fixed » Reviewed & tested by the community

@20

This is not the case for the 1.x series.

3.x was resolved in #3254097: Group's use of uasort returns booleans, switch to spaceship operator., though that issue should have been marked as a dupe, as this issue covers multiple branches and predates it.

masoom2206’s picture

StatusFileSize
new1.02 KB

Patch in #2 works for me as well. But it not for drupal/group (1.6.0).
So here is the patch for drupal/group (1.6.0)

I have added new patch here: https://www.drupal.org/project/group/issues/3210808#comment-15246841

zcht’s picture

The patch #2 also works excellently under Group 1.6.

@masoom2206 What makes you think it doesn't work? Your patch is, by the way, a 1:1 copy, no difference to patch #2.

masoom2206’s picture

StatusFileSize
new1.02 KB

@zcht, The issue is related to line number not match in drupal/group (1.6.0).
sorry for wrong patch uploaded. I have attached here the updated patch for drupal/group (1.6.0).

masoom2206’s picture

jordik’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

The patch from #3254097: Group's use of uasort returns booleans, switch to spaceship operator. applies perfectly to Group 1.6 and was already committed to 3.x.

magdalenaa67’s picture

#24 /uasort-comparison-3210808-2.patch worked for me in Group 1.6, Core 9.5.11 - Thank you!