function field_form_element_after_build

After-build callback for field elements in a form.

This stores the final location of the field within the form structure so that field_default_form_errors() can assign validation errors to the right form element.

Parameters

$element: The form element.

$form_state: An associative array containing the current state of the form.

Return value

The $element array that was passed in as a parameter.

See also

field_default_form_errors()

1 string reference to 'field_form_element_after_build'
WidgetBase::form in drupal/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php
Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::form().

File

drupal/core/modules/field/field.form.inc, line 102
Field forms management.

Code

function field_form_element_after_build($element, &$form_state) {
  $parents = $element['#field_parents'];
  $field_name = $element['#field_name'];
  $langcode = $element['#language'];
  $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state);
  $field_state['array_parents'] = $element['#array_parents'];
  field_form_set_state($parents, $field_name, $langcode, $form_state, $field_state);
  return $element;
}