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.

Parameters

$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

\Drupal\Core\Field\WidgetBase::formSingleElement()

hook_field_widget_form_alter()

Related topics

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

File

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

Code

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';
}
doc_Drupal
2016-10-29 09:18:12
Comments
Leave a Comment

Please login to continue.