You are here

protected function LayoutParagraphsWidget::extractInput in Layout Paragraphs 1.0.x

Extracts field value from form_state if it exists.

1 call to LayoutParagraphsWidget::extractInput()
LayoutParagraphsWidget::formElement in src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php, line 1377

Class

LayoutParagraphsWidget
Entity Reference with Layout field widget.

Namespace

Drupal\layout_paragraphs\Plugin\Field\FieldWidget

Code

protected function extractInput(array $form, FormStateInterface $form_state, int $delta, $element_name, $default_value = '') {
  $input = $form_state
    ->getUserInput();
  $parents = $form['#parents'];
  $key_exists = NULL;
  if (is_array($element_name)) {
    $element_path = array_merge($parents, [
      $this->fieldName,
      $delta,
    ], $element_name);
  }
  else {
    $element_path = array_merge($parents, [
      $this->fieldName,
      $delta,
      $element_name,
    ]);
  }
  $val = NestedArray::getValue($input, $element_path, $key_exists);
  if ($key_exists) {
    return Html::escape($val);
  }
  return $default_value;
}