function hook_field_widget_multivalue_WIDGET_TYPE_form_alter
Same name in other branches
- 8.9.x core/modules/field/field.api.php \hook_field_widget_multivalue_WIDGET_TYPE_form_alter()
Alter multi-value widget forms for a widget provided by another module.
Modules can implement hook_field_widget_multivalue_WIDGET_TYPE_form_alter() to modify a specific widget form, rather than using hook_field_widget_form_alter() and checking the widget type.
To alter the individual elements within the widget, loop over \Drupal\Core\Render\Element::children($elements).
Parameters
array $elements: The field widget form elements as constructed by \Drupal\Core\Field\WidgetBase::formMultipleElements().
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $context: An associative array. See hook_field_widget_multivalue_form_alter() for the structure and content of the array.
Deprecated
in drupal:9.2.0 and is removed from drupal:10.0.0. Use hook_field_widget_complete_WIDGET_TYPE_form_alter instead.
See also
https://www.drupal.org/node/3180429
\Drupal\Core\Field\WidgetBaseInterface::form()
\Drupal\Core\Field\WidgetBase::formMultipleElements()
hook_field_widget_multivalue_form_alter()
Related topics
File
-
core/
modules/ field/ field.api.php, line 441
Code
function hook_field_widget_multivalue_WIDGET_TYPE_form_alter(array &$elements, \Drupal\Core\Form\FormStateInterface $form_state, array $context) {
// Code here will only act on widgets of type WIDGET_TYPE. For example,
// hook_field_widget_multivalue_mymodule_autocomplete_form_alter() will only
// act on widgets of type 'mymodule_autocomplete'.
// Change the autocomplete route for each autocomplete element within the
// multivalue widget.
foreach (Element::children($elements) as $delta => $element) {
$elements[$delta]['#autocomplete_route_name'] = 'mymodule.autocomplete_route';
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.