Currently field widget forms are not alter-able. If one has a need to alter widget form or how it behaves one needs to copy/paste that code into it's own module and modify it there. this is very anti form-api. i consider this missing feature a critical bug. marking it a normal for now hoping those that worked on field api will elaborate on what's going on with this feature.

Comments

yched’s picture

Closest existing thing currently is hook_field_attach_form(), that is called at the end of field_attach_form() and lets you alter the form parts generated by Field API - includes all the fields in the object.

litwol’s picture

Alas using hook_field_attach_form() is the same as hook_form_alter(). What i am after is altering the form on widget level before it is added to the rest of the form; That way we dont have to guess where the form is inserted or have to parse the form tree to find the right widget.

moshe weitzman’s picture

Not sure you will be happy, but you can add a #process to all textfields by altering element_info (or textarea, select, button, ...). Then you get a chance to make changes .

The current situation is not "anti-form api". can you intercept every time any other modules attaches its stuff to any form?

chx’s picture

Moshe, that's totally not a solution, a widget can contain many elements -- and while I do not expect to be able to alter any one-off, unstructured form like that but widgets are different.

cyberwolf’s picture

Subscribing.

anrikun’s picture

This used to be possible with D6 CCK by implementing hook_widget_settings_alter()
Any news about this issue?

anrikun’s picture

Status: Active » Closed (duplicate)
anrikun’s picture

Title: Field widget form alter » hook_widget_settings_alter() is missing in D7 (and D8) and several D6 modules cannot be ported to D7 because of this.
Version: 7.x-dev » 8.x-dev
Category: task » bug
Priority: Normal » Major
Status: Closed (duplicate) » Active

Well I guess it is time to reopen this issue as #982764: Document how to upgrade CCK field modules that used hook_widget_settings_alter has been moved to the documentation project and gets absolutely no real progress there.

Somebody will tell us again that this is not a bug. But:
- Things that were possible in D6 are no longer possible in D7: Isn't this a major bug?
- Several modules are dying because of this, e.g.
http://drupal.org/project/imagefield_focus
http://drupal.org/project/ad_gallery
http://drupal.org/project/node_repeat
- This is not a documentation bug as nobody has been able to a provide any viable solution to this so far (See #982764: Document how to upgrade CCK field modules that used hook_widget_settings_alter)
- If it was only a documentation issue, then hook_widget_settings_alter() would not have been added to CCK (See #417122: Allow drupal_alter() on Field and Widget Settings)

bryancasler’s picture

animelion

yched’s picture

I did let #982764: Document how to upgrade CCK field modules that used hook_widget_settings_alter drop out of my radar.

Current way :
- use hook_field_widget_info_alter() to expose your additional settings
- use hook_form_field_ui_field_edit_form_alter() to add the form elements to edit the settings in the Field UI screen. If placed properly, the submitted values get saved automatically in the $instance['widget']['settings'] definition.
- use hook_field_attach_form() to alter the actual widgets in entity edit forms. You have to navigate through the $form to the location of the widgets you want to affect (in $form[$field_name][$langcode], the rest depends on the shape of the widget you want to alter), but the D6 versions probably had to do something similar. That part will get easier if/when #1204230: Missing hook_field_widget_form_alter() lands.

bleen’s picture

sub

damien tournoud’s picture

Status: Active » Closed (duplicate)

This is definitely a doc issue. Let's fix it in the other issue.

anrikun’s picture

FYI, this issue has been fixed in code: it was definitely not a documentation issue!
#1204230: Missing hook_field_widget_form_alter()