The new field widget hook hook_field_widget_complete_form_alter
(hook_field_widget_complete_WIDGET_TYPE_form_alter
) was introduced to make it possible to alter the whole widget form after it was proccessed.
In favor of this new hook, hook_field_widget_multivalue_form_alter
(hook_field_widget_multivalue_WIDGET_TYPE_form_alter
) were marked as deprecated and will be removed in Drupal 10.
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'];
Also hook_field_widget_form_alter
(hook_field_widget_WIDGET_TYPE_form_alter
) was marked as deprecated and will be replaced by hook_field_widget_single_element_form_alter
(hook_field_widget_single_element_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.