Fatal error: Unsupported operand types in /.../sites/all/modules/contrib/role_delegation/role_delegation.module on line 247

The problem is that single_user_role module has converted checkboxes => radios, and so the underlying data is stored as integers rather than arrays.

Comments

dalin’s picture

Assigned: dalin » Unassigned
Status: Active » Needs review
StatusFileSize
new1.37 KB
dalin’s picture

Holy cats, that was terrible code, yet somehow still worked. Try again.

bessone’s picture

Patch #2 it's working for me.

IRuslan’s picture

From my point of view, the idea to use user_presave hook is wrong.
It's error-prone in many similar situations (i.e. #2646668: hook_user_presave).
Any validation of user_presave with order higher than module's one will get a fatal error.

My proposition is to move logic to change structure back into an array in the validate handler of form.

Tested patch with proof of concept in the attachment.

Status: Needs review » Needs work

The last submitted patch, 4: 7.x-1.3-single_user_role-hook_user_presave-2375077-4.patch, failed testing.

IRuslan’s picture

StatusFileSize
new1.59 KB

Re-roll patch with disabled testing - we have no tests for the module.

IRuslan’s picture

Status: Needs work » Needs review
upunkt’s picture

While not using the Role Delegation module as companion I was getting notices like
Notice: Undefined index: roles in single_user_role_user_presave() (line 81 ...
and observing that assigned single user roles got discarded on calling user_presave() in a custom module. This phenomenon is described in https://www.drupal.org/node/2646668 also.

Looking at the code, I changed line 78 from

if (!is_array($edit['roles'])) {

to

if (isset($edit['roles']) && !is_array(!empty($edit['roles']))) {

and got it working for my usecase.

Still, I think IRuslan is right to move the logic. Consequently, his patch #6 does also work.

mrpauldriver’s picture

Issue summary: View changes
StatusFileSize
new159.09 KB

I am seeing as variation of this issue and the patch at #6 does not help.

I am seeing anomalies and errors on the user registration page. See screenshot

gbisht’s picture

@MrPaulDriver your issue seems to be little different and will be handled separately in https://www.drupal.org/project/single_user_role/issues/3012822

  • gulab.bisht committed 23a1437 on 7.x-1.x authored by IRuslan
    Issue #2375077 by dalin, IRuslan: Fatal error in hook_user_presave()...
gbisht’s picture

Status: Needs review » Fixed
gbisht’s picture

Status: Fixed » Closed (fixed)