Change record status: 
Project: 
Introduced in branch: 
9.2.x
Introduced in version: 
9.2.0
Description: 

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).

Impacts: 
Module developers

Comments

yas’s picture

hook_field_widget_multiple_form_alter(hook_field_widget_multiple_WIDGET_TYPE_form_alter) should be hook_field_widget_multivalue_form_alter (hook_field_widget_multivalue_WIDGET_TYPE_form_alter).

aaron.ferris’s picture

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) {

mlncn’s picture

Yeah, it's a bad habit in documentation to not include the use statement, which in this case is:

use Drupal\Core\Form\FormStateInterface;

because they typically are placed at the top of the file.

benjamin, Agaric

aaron.ferris’s picture

Yes indeed, we need something for anyone copying like for like. My example/use, either is fine imo, most documentation follows the former.