function hook_field_widget_WIDGET_TYPE_form_alter
Same name in other branches
- 9 core/modules/field/field.api.php \hook_field_widget_WIDGET_TYPE_form_alter()
- 8.9.x core/modules/field/field.api.php \hook_field_widget_WIDGET_TYPE_form_alter()
Alter widget forms for a specific widget provided by another module.
Modules can implement hook_field_widget_WIDGET_TYPE_form_alter() to modify a specific widget form, rather than using hook_field_widget_form_alter() and checking the widget type.
Parameters
$element: The field widget form element as constructed by hook_field_widget_form().
$form_state: An associative array containing the current state of the form.
$context: An associative array containing the following key-value pairs, matching the arguments received by hook_field_widget_form():
- "form": The form structure where widgets are being attached to. This might be a full form structure, or a sub-element of a larger form.
- "field": The field structure.
- "instance": The field instance structure.
- "langcode": The language associated with $items.
- "items": Array of default values for this field.
- "delta": The order of this item in the array of subelements (0, 1, 2, etc).
See also
hook_field_widget_form_alter()
Related topics
File
-
modules/
field/ field.api.php, line 956
Code
function hook_field_widget_WIDGET_TYPE_form_alter(&$element, &$form_state, $context) {
// Code here will only act on widgets of type WIDGET_TYPE. For example,
// hook_field_widget_mymodule_autocomplete_form_alter() will only act on
// widgets of type 'mymodule_autocomplete'.
$element['#autocomplete_path'] = 'mymodule/autocomplete_path';
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.