You are here

public static function ParagraphsWidget::addMoreSubmit in Paragraphs 8

Submission handler for the "Add another item" button.

Overrides WidgetBase::addMoreSubmit

File

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

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

public static function addMoreSubmit(array $form, FormStateInterface $form_state) {
  $submit = ParagraphsWidget::getSubmitElementInfo($form, $form_state);
  if ($submit['widget_state']['real_item_count'] < $submit['element']['#cardinality'] || $submit['element']['#cardinality'] == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
    $field_path = array_merge($submit['element']['#field_parents'], [
      $submit['element']['#field_name'],
    ]);
    $add_more_delta = NestedArray::getValue($submit['element'], [
      'add_more',
      'add_more_delta',
      '#value',
    ]);
    static::prepareDeltaPosition($submit['widget_state'], $form_state, $field_path, $add_more_delta);
  }
  if (isset($submit['button']['#bundle_machine_name'])) {
    $submit['widget_state']['selected_bundle'] = $submit['button']['#bundle_machine_name'];
  }
  else {
    $submit['widget_state']['selected_bundle'] = $submit['element']['add_more']['add_more_select']['#value'];
  }
  $submit['widget_state'] = static::autocollapse($submit['widget_state']);
  static::setWidgetState($submit['parents'], $submit['field_name'], $form_state, $submit['widget_state']);
  $form_state
    ->setRebuild();
}