You are here

public function FieldWidgetComponent::extractFormValues in Flexiform 8

Extract the form values.

Parameters

array $form: The section of the form corresponding to this component.

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

Overrides FormComponentInterface::extractFormValues

File

src/Plugin/FormComponentType/FieldWidgetComponent.php, line 161

Class

FieldWidgetComponent
Component class for field widgets.

Namespace

Drupal\flexiform\Plugin\FormComponentType

Code

public function extractFormValues(array $form, FormStateInterface $form_state) {
  $original_parents = $form['#parents'];
  array_pop($original_parents);
  $form = [
    '#parents' => $original_parents,
    $this->name => $form,
  ];
  if (strpos($this->name, ':')) {
    list($namespace, $field_name) = explode(':', $this->name, 2);
  }
  else {
    $namespace = '';
    $field_name = $this->name;
  }

  // Get the entity object.
  if ($context = $this
    ->getFormEntityManager()
    ->getContext($namespace)) {
    $entity_object = $context
      ->getContextValue();
    $items = $entity_object->{$field_name};
    if ($widget = $this
      ->getRenderer()) {
      $widget
        ->extractFormValues($items, $form, $form_state);
    }
  }
}