Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
drupal_prepare_form() works hard to pass $form_state by reference to hook_form_alter() and hook_form_FORM_ID_alter()...
// Normally, we would call drupal_alter($form_id, $form, $form_state).
// However, drupal_alter() normally supports just one byref parameter. Using
// the __drupal_alter_by_ref key, we can store any additional parameters
// that need to be altered, and they'll be split out into additional params
// for the hook_form_alter() implementations.
// @todo: Remove this in Drupal 7.
$data = &$form;
$data['__drupal_alter_by_ref'] = array(&$form_state);
drupal_alter('form_'. $form_id, $data);
This fact is documented for hook_form_FORM_ID_alter(), but not for hook_form_alter():
function hook_form_alter(&$form, $form_state, $form_id) { }
Comment | File | Size | Author |
---|---|---|---|
#10 | system.api_.php_.patch | 867 bytes | lyaunzbe |
#9 | hook_form_alterUpdate.patch | 637 bytes | lyaunzbe |
#6 | hook_form_alterUpdate.patch | 898 bytes | lyaunzbe |
#3 | hook_form_alterUpdate.patch | 896 bytes | lyaunzbe |
Comments
Comment #1
lyaunzbe CreditAttribution: lyaunzbe commentedFirst time contributor here and I'd like to attempt this if possible. If my understanding is correct, you simply want to mention, in a comment above the function hook_form_alter():, that modification for the form with the given form ID ($form_state) is passed to its parameters? I just want to make sure I'm understanding the bug correctly before proceeding. Thanks
Comment #2
BerdirA comment might not even be necessary, if you replace $form_state with &$form_state, that should be enough to indicate that it is by reference. Feel free to add a explaining comment too, if it makes sense for you.
Comment #3
lyaunzbe CreditAttribution: lyaunzbe commentedMy first attempt. Changed the form_state @param description and the parameter itself.
Comment #4
lyaunzbe CreditAttribution: lyaunzbe commentedComment #6
lyaunzbe CreditAttribution: lyaunzbe commentedOkay. Diff'd from the correct, root folder this time. Hopefully it passes now :)
Comment #7
BerdirI am not so sure about the comment. The thing is that we usually don't document that something is by reference (as you can see it from the function definition) and neither does $form have such a comment. So, just from reading the apidocs, I'd assume that only $form_state is by reference..
Comment #8
Damien Tournoud CreditAttribution: Damien Tournoud commented@lyaunzbe: Thanks for working on this! I agree with Berdir, we don't usually add in comments that a variable is passed by reference. Could you reroll the patch without this change?
Comment #9
lyaunzbe CreditAttribution: lyaunzbe commentedSorry. Rerolled.
Comment #10
lyaunzbe CreditAttribution: lyaunzbe commentedUsing cvs diff this time, rather than regular diff.
Comment #11
Damien Tournoud CreditAttribution: Damien Tournoud commentedPerfect, thanks!
Comment #12
Dries CreditAttribution: Dries commentedWelcome lyaunzbe! I committed your patch to CVS HEAD. Thanks.
Looking forward to more patches and other contributions. :)