The hooks hook_field_widget_multivalue_form_alter (hook_field_widget_multivalue_WIDGET_TYPE_form_alter) and hook_field_widget_form_alter (hook_field_widget_WIDGET_TYPE_form_alter) have been marked as deprecated and will be removed in Drupal 10.
The new field widget hooks hook_field_widget_complete_form_alter (hook_field_widget_complete_WIDGET_TYPE_form_alter) were introduced to make it possible to alter the whole widget form after it was proccessed. This should be used instead of hook_field_widget_multivalue_form_alter (hook_field_widget_multivalue_WIDGET_TYPE_form_alter).
Before:
function MYMODULE_field_widget_multivalue_form_alter(&$elements, FormStateInterface $form_state, $context) {
After:
function MYMODULE_field_widget_complete_form_alter(&$field_widget_complete_form, FormStateInterface $form_state, $context) {
$elements = &$field_widget_complete_form['widget'];
The new field widget hooks hook_field_widget_single_element_form_alter (hook_field_widget_single_element_WIDGET_TYPE_form_alter) should be used instead of hook_field_widget_form_alter (hook_field_widget_WIDGET_TYPE_form_alter).
Comments
Misspelling of hook_field_widget_multiple_form_alter
hook_field_widget_multiple_form_alter(hook_field_widget_multiple_WIDGET_TYPE_form_alter) should behook_field_widget_multivalue_form_alter(hook_field_widget_multivalue_WIDGET_TYPE_form_alter).Im seeing fatals calling this
Im seeing fatals calling this hook with the exact parameter structure as above
I think it should be
hook_field_widget_complete_form_alter(&$field_widget_complete_form, \Drupal\Core\Form\FormStateInterface $form_state, $context) {The documented signature works if there is a use statement first
Yeah, it's a bad habit in documentation to not include the use statement, which in this case is:
because they typically are placed at the top of the file.
benjamin, Agaric
Yes indeed, we need something
Yes indeed, we need something for anyone copying like for like. My example/use, either is fine imo, most documentation follows the former.