function hook_field_widget_complete_form_alter

Same name in other branches
  1. 9 core/modules/field/field.api.php \hook_field_widget_complete_form_alter()
  2. 10 core/modules/field/field.api.php \hook_field_widget_complete_form_alter()

Alter the complete form for field widgets provided by other modules.

Parameters

array $field_widget_complete_form: The field widget form element as constructed by \Drupal\Core\Field\WidgetBaseInterface::form().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

$context: An associative array containing the following key-value pairs:

  • form: The form structure to which widgets are being attached. This may be a full form structure, or a sub-element of a larger form.
  • widget: The widget plugin instance.
  • items: The field values, as a \Drupal\Core\Field\FieldItemListInterface object.
  • delta: The order of this item in the array of subelements (0, 1, 2, etc).
  • default: A boolean indicating whether the form is being shown as a dummy form to set default values.

See also

\Drupal\Core\Field\WidgetBaseInterface::form()

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

hook_field_widget_complete_WIDGET_TYPE_form_alter()

https://www.drupal.org/node/3180429

Related topics

3 string references to 'hook_field_widget_complete_form_alter'
FieldTestHooks::fieldWidgetCompleteFormAlter in core/modules/field/tests/modules/field_test/src/Hook/FieldTestHooks.php
Implements hook_field_widget_complete_form_alter().
MultipleWidgetFormTest::testFieldFormMultipleWidgetAlter in core/modules/field/tests/src/Functional/MultipleWidgetFormTest.php
Tests hook_field_widget_complete_form_alter().
MultipleWidgetFormTest::testFieldFormMultipleWidgetAlterSingleValues in core/modules/field/tests/src/Functional/MultipleWidgetFormTest.php
Tests hook_field_widget_complete_form_alter() with single value elements.

File

core/modules/field/field.api.php, line 291

Code

function hook_field_widget_complete_form_alter(&$field_widget_complete_form, FormStateInterface $form_state, $context) {
    $field_widget_complete_form['#attributes']['class'][] = 'my-class';
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.