Saving a new user who has no PbT associations (the "terms" field in their account is blank) produces the following exception:

Uncaught PHP Exception TypeError: "array_diff(): Argument #2 must be of type array, string given" at ...\modules\contrib\permissions_by_term\permissions_by_term.module line 312

Code in question is:

  // Rebuild permissions for nodes if needed.
  $origTerms = $form['access']['terms']['#default_value'] ?? [];
  $newTerms = $form_state->getValue('terms');  <--- returns "", not an array
  $changes = array_diff($origTerms, $newTerms) + array_diff($newTerms, $origTerms);  <--- failure here

Patch follows

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

_randy created an issue. See original summary.

_randy’s picture

FileSize
652 bytes
pacproduct’s picture

Status: Active » Needs review
FileSize
864 bytes

Facing this too.
Patch in #2 does make it work.

I'm wondering if we could not test whether the variable is an array directly though, as that's what array_diff is expecting. So we're sure it receives the right data type.

Attached patch is a suggestion with this approach + Comment explaining what the problem is.

  • marcoliver committed 9168e6a6 on 3.1.x-dev
    Issue #3388936 by _randy, pacproduct: New user save with no terms causes...
marcoliver’s picture

Status: Needs review » Fixed

Thanks! I've tested your patches and committed the changes to dev. Will be included in the next release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.