I need to hack core or a contrib module to alter default values.
My totally trivial use-case: I want to decrease the default #size for #type 'textfield' to 50 or even less. Doing this via CSS is a major clusterfuck, because then you have to add countless of further overrides to revert the width for textfields originally should be displayed with a larger/smaller #size.
Also, I cannot simply implement
function custom_elements() {
$type['textfield'] = array('#size' => 50);
return $type;
}
because that results in
<input type="text" class="form-text" value="" size="Array" id="edit-foo" name="foo" maxlength="128" />
I'm kindly asking to apply this fix to D6 as well.
Comments
Comment #1
damien tournoud commentedOh. That makes a *lot* of sense.
Another use case: I want to implement a feature that modify the behavior of some form elements (via a special #process function). To do that currently you have to implement hook_form_alter() and alter all form elements manually. But if you do so, you remove the right of the form to override the #process function ;(
I support the backport as well.
Comment #2
sunThanks!
Same patch for D6.
Comment #3
webchickDocs plz.
Comment #4
sunAdded docs.
Comment #5
dropcube commentedThat makes sense, patch seems OK.
Comment #6
webchickThanks! Committed to HEAD. I'm not sure what Gábor's feelings will be on 6.x, but moving down there for consideration. Needs porting since #2 doesn't have the comment #4 does.
Comment #7
sunRe-rolled for D6 with additional inline comment.
Hook documentation lives elsewhere for D6.
Comment #8
cwgordon7 commentedFrom what I gather, hook_element_info_alter() will be run once for all elements - if this is the case, the Drupal 7 api docs probably need to be updated to a $types parameter rather than a $type?
Comment #9
sun@cwgordon7: $type (singular) is - currently - consistent with the other functions and hooks in core, they all use $type, not $types. hook_element_info() itself does not seem to be documented, but all implementations in core use $type. Additionally, registry function itself, http://api.drupal.org/api/function/element_info/7, also uses $type.
Comment #10
gábor hojtsyMy thinking on this is that this is clearly a new feature, and those are not added to Drupal 6.