public function InlineParagraphsWidget::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/ InlineParagraphsWidget.php, line 1286  
Class
- InlineParagraphsWidget
 - Plugin implementation of the 'entity_reference paragraphs' widget.
 
Namespace
Drupal\paragraphs\Plugin\Field\FieldWidgetCode
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);
  $remove_mode_item_count = $this
    ->getNumberOfParagraphsInMode($widget_state, 'remove');
  $non_remove_mode_item_count = $widget_state['real_item_count'] - $remove_mode_item_count;
  if ($elements['#required'] && $non_remove_mode_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);
}