public static function InlineParagraphsWidget::addMoreSubmit

File

paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 1167

Class

InlineParagraphsWidget
Plugin implementation of the 'entity_reference paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

public static function addMoreSubmit(array $form, FormStateInterface $form_state) {
  $button = $form_state
    ->getTriggeringElement();

  // Go one level up in the form, to the widgets container.
  $element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2));
  $field_name = $element['#field_name'];
  $parents = $element['#field_parents'];

  // Increment the items count.
  $widget_state = static::getWidgetState($parents, $field_name, $form_state);
  if ($widget_state['real_item_count'] < $element['#cardinality'] || $element['#cardinality'] == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
    $widget_state['items_count']++;
  }
  if (isset($button['#bundle_machine_name'])) {
    $widget_state['selected_bundle'] = $button['#bundle_machine_name'];
  }
  else {
    $widget_state['selected_bundle'] = $element['add_more']['add_more_select']['#value'];
  }
  static::setWidgetState($parents, $field_name, $form_state, $widget_state);
  $form_state
    ->setRebuild();
}