You are here

public function ParagraphsWidget::multipleElementValidate in Paragraphs 8

Special handling to validate form elements with multiple values.

Parameters

array $elements: An associative array containing the substructure of the form to be validated in this call.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $form: The complete form array.

File

src/Plugin/Field/FieldWidget/ParagraphsWidget.php, line 2210

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

public function multipleElementValidate(array $elements, FormStateInterface $form_state, array $form) {
  $field_name = $this->fieldDefinition
    ->getName();
  $widget_state = static::getWidgetState($elements['#field_parents'], $field_name, $form_state);
  if ($elements['#required'] && $widget_state['real_item_count'] < 1) {
    $form_state
      ->setError($elements, $this
      ->t('@name field is required.', [
      '@name' => $this->fieldDefinition
        ->getLabel(),
    ]));
  }
  static::setWidgetState($elements['#field_parents'], $field_name, $form_state, $widget_state);
}