public function ParagraphsWidget::flagErrors

File

paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php, line 2507

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

public function flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state) {
  $field_name = $this->fieldDefinition
    ->getName();
  $field_state = static::getWidgetState($form['#parents'], $field_name, $form_state);

  // In dragdrop mode, validation errors can not be mapped to form elements,
  // add them on the top level widget element.
  if (!empty($field_state['dragdrop'])) {
    if ($violations
      ->count()) {
      $element = NestedArray::getValue($form_state
        ->getCompleteForm(), $field_state['array_parents']);
      foreach ($violations as $violation) {
        $form_state
          ->setError($element, $violation
          ->getMessage());
      }
    }
  }
  else {
    return parent::flagErrors($items, $violations, $form, $form_state);
  }
}