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.
It might be useful (and coherent ?) to have the #after_build property specify an array of callbacks instead of a single callback (just like #pre_render callbacks are handled)
That way, several form_alter hooks could add their own #after_build callbacks whithout discarding the ones previously set.
BTW, why do the #after_build callbacks have to return the new $form value ? They could just modify the $form itself, couldn't they ? (outside the scope of this patch, though)
Comment | File | Size | Author |
---|---|---|---|
#11 | after_build_4.patch | 3.65 KB | tenrapid |
#8 | after_build_array_1.patch | 3.47 KB | yched |
#1 | after_build_array_0.patch | 3.41 KB | yched |
after_build_array.patch | 1.95 KB | yched | |
Comments
Comment #1
yched CreditAttribution: yched commentedForgot system.module in my previous patch.
Comment #2
moshe weitzman CreditAttribution: moshe weitzman commentedmakes sense to me. chx, hunmonk - any comment?
Comment #3
chx CreditAttribution: chx commentedWell, it makes sense but $a['x'][] does not cut it. Define the arrays properly $a['x'] = array('functioname');
Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentedchx: why? that [] is perfectly valid syntax, even if the array does not exist already. php does not throw even a NOTICE. I showed this same syntax to Goba a while ago and he was suprised, but agreed that it is supported syntax. The array docs say so.
Comment #5
yched CreditAttribution: yched commentedWell, I used that syntax precisely because It ensured that no pre-existing value was discarded,
while saving any (IMHO tedious) 'if (isset($thingy['#after_build'])) { [] syntax} else {new array syntax}' code.
But I can post a 'stricter' version if you really think the '[] syntax' is definitely too loose.
Comment #6
chx CreditAttribution: chx commentedI can not remember what PHP throws (E_STRICT?) but I do remember that the rule of thumb is that [] does not define an array while ['x'] does. Ie if $a is not defined then $a[] is not good.
Comment #7
moshe weitzman CreditAttribution: moshe weitzman commentedi hope you will be convinced by the php docs themselves: http://www.php.net/manual/en/language.types.array.php#language.types.arr.... i've tested this - PHP does not throw any error, not even a notice, when you define an array using square brackets.
Comment #8
yched CreditAttribution: yched commentedForget about that.
The argued assignements (in node.module and comment.module) happen on form creation time, so $form['#after_build'] is empty anyway.
I should have looked better - sorry for the fuss...
Comment #9
chx CreditAttribution: chx commentedWhat tenrapid outlines in http://drupal.org/node/58892 makes this issue an absolute must.
Comment #10
chx CreditAttribution: chx commentedHm, I have a better idea for tenrapid's issue then a last minute API change.
Comment #11
tenrapid CreditAttribution: tenrapid commentedThis patch adds back the missing
$form['#after_build_done'] = TRUE;
.Tested and works within core.
Comment #12
chx CreditAttribution: chx commentedWell, it turns out that preview is an #after_build which happens before #validate so this goes back to critical. And tenrapid tested the patch -- which is quite trivial.
Comment #13
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedapplied
Comment #14
Tobias Maier CreditAttribution: Tobias Maier commentedComment #15
(not verified) CreditAttribution: commented