You are here

protected function EntityField::getFormStateValue in Entity Field Condition 2.0.x

Get the form state value.

Parameters

mixed $key: The value key.

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

mixed|null $default: The default value.

bool $checkEmpty: Check if the value is empty.

Return value

mixed The value for the property.

1 call to EntityField::getFormStateValue()
EntityField::buildConfigurationForm in src/Plugin/Condition/EntityField.php
Form constructor.

File

src/Plugin/Condition/EntityField.php, line 489

Class

EntityField
Define the entity field condition base class.

Namespace

Drupal\entity_field_condition\Plugin\Condition

Code

protected function getFormStateValue($key, FormStateInterface $form_state, $default = NULL, bool $checkEmpty = FALSE) {
  $key = !is_array($key) ? [
    $key,
  ] : $key;
  $inputs = [
    $form_state
      ->getValues(),
    $form_state
      ->getUserInput(),
  ];
  foreach ($inputs as $input) {
    $key_exist = FALSE;
    $value = NestedArray::getValue($input, $key, $key_exist);
    if ($key_exist) {
      if ($checkEmpty === TRUE && empty($value)) {
        continue;
      }
      return $value;
    }
  }
  return $default;
}