Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#3 | wsod-user-save-no-term-3388936-3.patch | 864 bytes | pacproduct |
#2 | issue-3388936.patch | 652 bytes | _randy |
Comments
Comment #2
_randy CreditAttribution: _randy commentedComment #3
pacproduct CreditAttribution: pacproduct at Makina Corpus commentedFacing 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.
Comment #5
marcoliverThanks! I've tested your patches and committed the changes to dev. Will be included in the next release.