You are here

public function EntityFormDisplay::extractFormValues in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php \Drupal\Core\Entity\Entity\EntityFormDisplay::extractFormValues()

Extracts field values from the submitted widget values into the entity.

This accounts for drag-and-drop reordering of field values, and filtering of empty values.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity.

array $form: The form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.

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

Return value

array An array whose keys and values are the keys of the top-level entries in $form_state->getValues() that have been processed. The remaining entries, if any, do not correspond to widgets and should be extracted manually by the caller if needed.

Overrides EntityFormDisplayInterface::extractFormValues

File

core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php, line 231

Class

EntityFormDisplay
Configuration entity that contains widget options for all components of an entity form in a given form mode.

Namespace

Drupal\Core\Entity\Entity

Code

public function extractFormValues(FieldableEntityInterface $entity, array &$form, FormStateInterface $form_state) {
  $extracted = [];
  foreach ($entity as $name => $items) {
    if ($widget = $this
      ->getRenderer($name)) {
      $widget
        ->extractFormValues($items, $form, $form_state);
      $extracted[$name] = $name;
    }
  }
  return $extracted;
}