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)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

FileSize
3.41 KB

Forgot system.module in my previous patch.

moshe weitzman’s picture

makes sense to me. chx, hunmonk - any comment?

chx’s picture

Status: Needs review » Needs work

Well, it makes sense but $a['x'][] does not cut it. Define the arrays properly $a['x'] = array('functioname');

moshe weitzman’s picture

chx: 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.

yched’s picture

Well, 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.

chx’s picture

I 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.

moshe weitzman’s picture

i 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.

yched’s picture

Status: Needs work » Needs review
FileSize
3.47 KB

Forget 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...

chx’s picture

Title: #after_build : single function => functions array ? » Turn #after_build into a functions array
Assigned: Unassigned » chx
Category: feature » task
Priority: Normal » Critical

What tenrapid outlines in http://drupal.org/node/58892 makes this issue an absolute must.

chx’s picture

Category: task » feature
Priority: Critical » Normal

Hm, I have a better idea for tenrapid's issue then a last minute API change.

tenrapid’s picture

FileSize
3.65 KB

This patch adds back the missing $form['#after_build_done'] = TRUE;.

Tested and works within core.

chx’s picture

Category: feature » task
Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

Well, 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.

killes@www.drop.org’s picture

applied

Tobias Maier’s picture

Status: Reviewed & tested by the community » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)