Closed (duplicate)
Project:
Drupal core
Version:
8.0.x-dev
Component:
field system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
2 Jan 2010 at 14:00 UTC
Updated:
29 Jul 2014 at 18:35 UTC
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
Comment #1
yched commentedClosest 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.
Comment #2
litwol commentedAlas 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.
Comment #3
moshe weitzman commentedNot 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?
Comment #4
chx commentedMoshe, 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.
Comment #5
cyberwolf commentedSubscribing.
Comment #6
anrikun commentedThis used to be possible with D6 CCK by implementing
hook_widget_settings_alter()Any news about this issue?
Comment #7
anrikun commentedMarking this as a duplicate of #982764: Document how to upgrade CCK field modules that used hook_widget_settings_alter
Comment #8
anrikun commentedWell 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)Comment #9
bryancasler commentedanimelion
Comment #10
yched commentedI 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.
Comment #11
bleen commentedsub
Comment #12
damien tournoud commentedThis is definitely a doc issue. Let's fix it in the other issue.
Comment #13
anrikun commentedFYI, this issue has been fixed in code: it was definitely not a documentation issue!
#1204230: Missing hook_field_widget_form_alter()