/Drupal 8

function hook_field_widget_WIDGET_TYPE_form_alter

hook_field_widget_WIDGET_TYPE_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $form_state, $context)

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.


$element: The field widget form element as constructed by hook_field_widget_form().

$form_state: The current state of the form.

$context: An associative array. See hook_field_widget_form_alter() for the structure and content of the array.

See also



Related topics

Field Widget API
Define Field API widget types.
Define functions that alter the behavior of Drupal core.


core/modules/field/field.api.php, line 185
Field API documentation.


function hook_field_widget_WIDGET_TYPE_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $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_route_name'] = 'mymodule.autocomplete_route';

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.