You are here

protected function EntityExtraFieldForm::getEntityFormStateValue in Entity Extra Field 8

Same name and namespace in other branches
  1. 2.0.x src/Form/EntityExtraFieldForm.php \Drupal\entity_extra_field\Form\EntityExtraFieldForm::getEntityFormStateValue()

Get the form state value.

Parameters

string|array $key: The element key.

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

null $default: The default value if nothing is found.

Return value

mixed|null The form value; otherwise FALSE if the value can't be found.

3 calls to EntityExtraFieldForm::getEntityFormStateValue()
EntityExtraFieldForm::attachFieldTypeConditionForm in src/Form/EntityExtraFieldForm.php
Attach field type condition form.
EntityExtraFieldForm::createFieldTypeInstance in src/Form/EntityExtraFieldForm.php
Create extra field type plugin instance.
EntityExtraFieldForm::form in src/Form/EntityExtraFieldForm.php
Gets the actual form array to be built.

File

src/Form/EntityExtraFieldForm.php, line 519

Class

EntityExtraFieldForm
Define entity extra field form.

Namespace

Drupal\entity_extra_field\Form

Code

protected function getEntityFormStateValue($key, FormStateInterface $form_state, $default = NULL) {

  /** @var \Drupal\entity_extra_field\Entity\EntityExtraField $entity */
  $entity = $this->entity;
  $key = !is_array($key) ? [
    $key,
  ] : $key;
  $inputs = [
    $form_state
      ->cleanValues()
      ->getValues(),
  ];
  if ($entity
    ->id() !== NULL) {
    $inputs[] = $entity
      ->toArray();
  }
  foreach ($inputs as $input) {
    $value = NestedArray::getValue($input, $key, $key_exists);
    if (!isset($value) && !$key_exists) {
      continue;
    }
    return $value;
  }
  return $default;
}