Re: [development] form_builder and the $form['#type'] .'_value' callback.
I started asking chx about this in IRC last night. I've been working on a few custom form elements for handling files. I need a chance to save files locally before #validate is reached. Chx, suggested #after_build, but I am having issue with my #after_build being called from my element prototype(the default #type values returned from hook_element). While looking through form.inc and trying to figure out why my #after_build function wasn't being called when triggering a submit button on the page I notice there is a large select in form_builder for some default element types, to assign their values from edit/_POST. The _value callback is for defining default values according to chx, and is a rarely used function. I thought it might be a neat idea to move this hard coded select out of form_builder and use the _value callback to assign the #value in form_builder and set the #needs_validation if a value is return from the _value callback. Otherwise use the #default_value defined in the form or the element prototype. I think the behavior would make it easier to build form_elements that don't return a value (type=file ad unchecked type=checkbox are the only ones I know of) and need to generate their value from contextual data. .darrel.
Now, this makes more sense than it did last night. Yes. This is a good idea. Moving that switch into {$type}_value will let us add more elements easily and will not affect non-submitted forms where I am concerned about speed. I was also concerned about what will happen with the $form['#needs_validation'] = TRUE; part but that's also easy: currently _value does not return anything, not it will simply return needs_validation aka. return TRUE if you assigned #value based on $edit and then we can OR with required. Patch is forthcoming.
participants (2)
-
Darrel O'Pry -
Karoly Negyesi