public function ParagraphsWidget::flagErrors in Paragraphs 8
Reports field-level validation errors against actual form elements.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values.
\Symfony\Component\Validator\ConstraintViolationListInterface $violations: A list of constraint violations to flag.
array $form: The form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Overrides WidgetBase::flagErrors
File
- src/
Plugin/ Field/ FieldWidget/ ParagraphsWidget.php, line 2166
Class
- ParagraphsWidget
- Plugin implementation of the 'entity_reference_revisions paragraphs' widget.
Namespace
Drupal\paragraphs\Plugin\Field\FieldWidgetCode
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);
}
}