You are here

public function ProfileFormWidget::extractFormValues in Profile 8

Extracts field values from submitted form values.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values. This parameter is altered by reference to receive the incoming form values.

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.

Overrides WidgetBase::extractFormValues

File

src/Plugin/Field/FieldWidget/ProfileFormWidget.php, line 257

Class

ProfileFormWidget
Plugin implementation of the 'profile_form' widget.

Namespace

Drupal\profile\Plugin\Field\FieldWidget

Code

public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state) {
  if ($this
    ->isDefaultValueWidget($form_state)) {
    $items
      ->filterEmptyItems();
    return;
  }
  $property = [
    'profiles',
    $this
      ->getFieldSetting('profile_type'),
  ];
  $profile = $form_state
    ->get($property);
  if (!empty($profile)) {
    $values = [
      [
        'entity' => $profile,
      ],
    ];
    $items
      ->setValue($values);
    $items
      ->filterEmptyItems();
  }
}