You are here

public function InlineParagraphsWidget::elementValidate in Paragraphs 8

File

src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 1254

Class

InlineParagraphsWidget
Plugin implementation of the 'entity_reference paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

public function elementValidate($element, FormStateInterface $form_state, $form) {
  $field_name = $this->fieldDefinition
    ->getName();
  $widget_state = static::getWidgetState($element['#field_parents'], $field_name, $form_state);
  $delta = $element['#delta'];
  if (isset($widget_state['paragraphs'][$delta]['entity'])) {
    $entity = $widget_state['paragraphs'][$delta]['entity'];

    /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $display */
    $display = $widget_state['paragraphs'][$delta]['display'];
    if ($widget_state['paragraphs'][$delta]['mode'] == 'edit') {

      // Extract the form values on submit for getting the current paragraph.
      $display
        ->extractFormValues($entity, $element['subform'], $form_state);
      $display
        ->validateFormValues($entity, $element['subform'], $form_state);
    }
  }
  static::setWidgetState($element['#field_parents'], $field_name, $form_state, $widget_state);
}