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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

Status: Needs review » Reviewed & tested by the community

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

sun’s picture

Thanks!

Same patch for D6.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Docs plz.

sun’s picture

Status: Needs work » Needs review
FileSize
1.53 KB

Added docs.

dropcube’s picture

Status: Needs review » Reviewed & tested by the community

That makes sense, patch seems OK.

webchick’s picture

Version: 7.x-dev » 6.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Thanks! 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.

sun’s picture

Status: Patch (to be ported) » Reviewed & tested by the community
FileSize
607 bytes

Re-rolled for D6 with additional inline comment.

Hook documentation lives elsewhere for D6.

cwgordon7’s picture

From 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?

sun’s picture

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

Gábor Hojtsy’s picture

Version: 6.x-dev » 7.x-dev
Category: bug » feature
Status: Reviewed & tested by the community » Fixed

My thinking on this is that this is clearly a new feature, and those are not added to Drupal 6.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.