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.
the hook user expects a user object in its third parameter, $account.
however the user_register_validate function invokes the user hook sending an array instead...
user_module_invoke('validate', $form_state['values'], $form_state['values'], 'account');
This means that I can't user_access($account) in hook_user if $op == 'validate' because user_access expects an object, not an array.
The workaround is to user_access((object)$account);
I've a feeling I'm missing something here, but on the other hand, it's perfectly straight forward.
Comment | File | Size | Author |
---|---|---|---|
#26 | user_regiser_validate-720876-26-d6.patch | 948 bytes | pillarsdotnet |
#21 | user_register_validate-720876-21.patch | 880 bytes | pillarsdotnet |
#17 | user_register_validate-720876-17-D6.patch | 880 bytes | pillarsdotnet |
#14 | user_register_validate-720876-14.patch | 483 bytes | pillarsdotnet |
#12 | user_register_validate-720876-12.patch | 880 bytes | pillarsdotnet |
Comments
Comment #1
pillarsdotnet CreditAttribution: pillarsdotnet commentedSame problem here.
Patch solves the problem for me.
Comment #2
pillarsdotnet CreditAttribution: pillarsdotnet commentedThe bug has apparently been around as long as function itself: Mon, 21 Nov 2005.
Comment #3
pillarsdotnet CreditAttribution: pillarsdotnet commentedSlighly smaller/simpler patch; needs testing.
Comment #4
pillarsdotnet CreditAttribution: pillarsdotnet commentedTagging. Note that D7 likewise casts
$form_state['values']
to an object, in the entity_form_field_validate function.The user_register_validate function was created Mon, 21 Nov 2005, removed Sat, 10 Oct 2009, and recreated Tue, 30 Nov 2010.
So this patch is technically a backport of the fix incidental to:
Comment #5
pillarsdotnet CreditAttribution: pillarsdotnet commentedAffects CiviCRM -- that's how I found/fixed it in the first place.
Comment #6
pillarsdotnet CreditAttribution: pillarsdotnet commentedBetter title?
Comment #7
pillarsdotnet CreditAttribution: pillarsdotnet commentedI can't believe I'm bikeshedding this...
Comment #8
pillarsdotnet CreditAttribution: pillarsdotnet commentedPatch in #1 was the correct approach. Re-uploading for the sake of clarity.
Comment #9
Gábor HojtsyLooks good. Who else tested this?
Comment #10
pillarsdotnet CreditAttribution: pillarsdotnet commentedDunno, but at least one other person (the original reporter) was affected by the problem, and the suggested fix seems self-evident to me. The only other fix I could imagine is to move the cast to user_module_invoke():
Again, it seems self-evident that the patch in #1/#8 is preferable, especially since the D7 patch above is unnecessary and arguably wrong.
Comment #12
pillarsdotnet CreditAttribution: pillarsdotnet commentedTrying again...
Comment #14
pillarsdotnet CreditAttribution: pillarsdotnet commentedOkay, so the testbot doesn't like it when I follow instructions on how to submit patches.
Trying again with "git diff -no-prefix"
Comment #15
pillarsdotnet CreditAttribution: pillarsdotnet commentedGo, testbot!
Comment #17
pillarsdotnet CreditAttribution: pillarsdotnet commentedoh, tay.
so maybe testbot is trying (once again) to apply D6 patches to D8 core?
Comment #18
pillarsdotnet CreditAttribution: pillarsdotnet commentedComment #19
Gábor HojtsyDoes not seem like anybody tested this in the community beyond the patch creator?!
Comment #20
pillarsdotnet CreditAttribution: pillarsdotnet commentedI guess nobody cares about fixing long-standing bugs in the d6 api. I get quicker results with d8 bugs, in fact.
Added link on
user_register_validate()
api page.Comment #21
pillarsdotnet CreditAttribution: pillarsdotnet commentedRe-uploading; I think the testbots are fixed...
Comment #22
pillarsdotnet CreditAttribution: pillarsdotnet commented#21: user_register_validate-720876-21.patch queued for re-testing.
Comment #24
pillarsdotnet CreditAttribution: pillarsdotnet commentedOpened related #1192088: The user_register_validate() function is faulty and should be removed.
Comment #25
pillarsdotnet CreditAttribution: pillarsdotnet commented#21: user_register_validate-720876-21.patch queued for re-testing.
Comment #26
pillarsdotnet CreditAttribution: pillarsdotnet commentedRenaming patch to avoid useless core testing as suggested by ksenzee in IRC.
Comment #27
pillarsdotnet CreditAttribution: pillarsdotnet commentedOpened related #1192178: The user_module_invoke() function lacks documentation of parameters.
Comment #28
pwolanin CreditAttribution: pwolanin commentedSo, I've been testing this patch and related code. I think Drupal core masks the error due to the isset() check in function user_user(), so the rest of the code is never called when an anonymous user registers. However, any contrib module implementing hook_user('validate') will see a notice or worse from this bug, and according to the OP PHP 5.3 is less graceful in handling the case of an array accessed as an object.
This test code on PHP 5.2.6 gives me:
FALSE
TRUE
According to pillarsdotnet PHP 5.3 gives FALSE FALSE which reinforces the fact that 5.2 and 5.3 are different about this.
In any case - the patch is trivial and won't cause any harm and makes core respect its own API.
Comment #29
pillarsdotnet CreditAttribution: pillarsdotnet commented#21: user_register_validate-720876-21.patch queued for re-testing.
Comment #30
Gábor HojtsyCommitted, pushed, thanks.