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.
When calling user_save inside hook_user_login, if the $edit array is used (which you should use when using hook_user_insert)
Login will be aborted when using the drupal log in form since drupal is trying to save the full form_state to the user.
Comments
Comment #2
Vinay15Hi nicxvan,
The documentation about hook_user_login clearly states that $edit is "The array of form values submitted by the user." which is same as $form_state. So, I think this might not get changed.
And while using user_save in hook_user_login, you can use $edit['user'] object to save user data.
Thanks,
Vinay
Comment #3
Vinay15Comment #4
nicxvan CreditAttribution: nicxvan as a volunteer commentedThanks for the tip on $edit['user']
It seems the edit array here is used differently than other API's though and it performs more like a form_state as the documentation says, why would we not document it in the function call to prevent confusion.
Comment #5
Vinay15Yes, I totally agree with you that it should be stated as $form_state rather than $edit, but there might be some reason why it is called as $edit in the first place.
Comment #6
nicxvan CreditAttribution: nicxvan as a volunteer commentedIs there someone I can message that would know? Or should I comment on that api entry?
Comment #7
marcaddeo CreditAttribution: marcaddeo commentedI would agree with nicxvan here. I found the documentation was a bit unclear because of that as well and spent quite some time trying to figure out why it wasn't working, only to find out that $edit is actually $form_state.
I think updating the documentation makes sense to make it clear.
Comment #8
Vinay15Yes, commenting on that api would also get some replies and there are people on IRC who will also reply to the query.