function field_attach_extract_form_values

Populates an entity object with values from a form submission.

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

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity being submitted. The actual field values will be read from $form_state['values'].

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

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

array $options: An associative array of additional options. See field_invoke_method() for details.

Related topics

6 calls to field_attach_extract_form_values()
EditFieldForm::buildEntity in drupal/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php
Returns a cloned entity containing updated field values.
EntityFormControllerNG::buildEntity in drupal/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php
Overrides EntityFormController::buildEntity().
entity_form_submit_build_entity in drupal/core/includes/entity.inc
Copies submitted values to entity properties for simple entity forms.
FieldAttachOtherTest::testFieldAttachExtractFormValues in drupal/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
Test field_attach_extract_form_values().
field_test_entity_nested_form_submit in drupal/core/modules/field/tests/modules/field_test/field_test.entity.inc
Submit handler for field_test_entity_nested_form().

... See full list

File

drupal/core/modules/field/field.attach.inc, line 1137
Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.

Code

function field_attach_extract_form_values(EntityInterface $entity, $form, &$form_state, array $options = array()) {

  // Ensure we are working with a BC mode entity.
  $entity = $entity
    ->getBCEntity();

  // Extract field values from submitted values.
  $form_display = $form_state['form_display'];
  field_invoke_method('extractFormValues', _field_invoke_widget_target($form_display), $entity, $form, $form_state, $options);

  // Let other modules act on submitting the entity.
  // Avoid module_invoke_all() to let $form_state be taken by reference.
  foreach (module_implements('field_attach_extract_form_values') as $module) {
    $function = $module . 'field_attach_extract_form_values';
    $function($entity, $form, $form_state);
  }
}