interdiff impossible; taking evasive action reverted: --- b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php +++ a/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php @@ -391,30 +391,11 @@ '#paragraphs_mode' => 'edit', ); - $links['duplicate_button'] = array( - '#type' => 'submit', - '#value' => $this->t('Duplicate'), - '#name' => strtr($id_prefix, '-', '_') . '_duplicate', - '#weight' => 502, - '#submit' => array(array(get_class($this), 'duplicateSubmit')), - '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), - '#delta' => $delta, - '#ajax' => array( - 'callback' => array(get_class($this), 'addMoreAjax'), - 'wrapper' => $widget_state['ajax_wrapper_id'], - 'effect' => 'fade', - ), - '#access' => $paragraphs_entity->access('update'), - '#prefix' => '
  • ', - '#suffix' => '
  • ', - '#paragraphs_mode' => 'duplicate', - ); - $links['remove_button'] = array( '#type' => 'submit', '#value' => $this->t('Remove'), '#name' => strtr($id_prefix, '-', '_') . '_remove', + '#weight' => 502, - '#weight' => 503, '#submit' => array(array(get_class($this), 'paragraphsItemSubmit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), '#delta' => $delta, @@ -997,25 +978,6 @@ $form_state->setRebuild(); } - public static function duplicateSubmit(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, -4)); - $field_name = $element['#field_name']; - $parents = $element['#field_parents']; - - // Inserting new element in the array. - $field_state = static::getWidgetState($parents, $field_name, $form_state); - $delta = $button['#delta']; - array_splice($field_state['paragraphs'], $delta + 1, 0, $field_state['paragraphs'][$delta]); - $field_state['items_count']++; - $field_state['paragraphs'][$delta + 1]['entity'] = $field_state['paragraphs'][$delta]['entity']->createDuplicate(); - - static::setWidgetState($parents, $field_name, $form_state, $field_state); - - $form_state->setRebuild(); - } - public static function paragraphsItemSubmit(array $form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); unchanged: --- a/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php +++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php @@ -391,11 +391,30 @@ class InlineParagraphsWidget extends WidgetBase { '#paragraphs_mode' => 'edit', ); + $links['duplicate_button'] = array( + '#type' => 'submit', + '#value' => $this->t('Duplicate'), + '#name' => strtr($id_prefix, '-', '_') . '_duplicate', + '#weight' => 502, + '#submit' => array(array(get_class($this), 'duplicateSubmit')), + '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), + '#delta' => $delta, + '#ajax' => array( + 'callback' => array(get_class($this), 'itemAjax'), + 'wrapper' => $widget_state['ajax_wrapper_id'], + 'effect' => 'fade', + ), + '#access' => $paragraphs_entity->access('update'), + '#prefix' => '
  • ', + '#suffix' => '
  • ', + '#paragraphs_mode' => 'duplicate', + ); + $links['remove_button'] = array( '#type' => 'submit', '#value' => $this->t('Remove'), '#name' => strtr($id_prefix, '-', '_') . '_remove', - '#weight' => 502, + '#weight' => 503, '#submit' => array(array(get_class($this), 'paragraphsItemSubmit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), '#delta' => $delta, @@ -963,6 +982,30 @@ class InlineParagraphsWidget extends WidgetBase { $form_state->setRebuild(); } + public static function duplicateSubmit(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, -4)); + $field_name = $element['#field_name']; + $parents = $element['#field_parents']; + + // Inserting new element in the array. + $field_state = static::getWidgetState($parents, $field_name, $form_state); + $delta = $button['#delta']; + $field_state['items_count']++; + $field_state['real_item_count']++; + $field_state['original_deltas'] = array_merge($field_state['original_deltas'], ['1' => 1]) ; + + $field_state['paragraphs'][] = [ + 'entity' => $field_state['paragraphs'][$delta]['entity']->createDuplicate(), + 'display' => $field_state['paragraphs'][$delta]['display'], + 'mode' => 'closed' + ]; + + static::setWidgetState($parents, $field_name, $form_state, $field_state); + $form_state->setRebuild(); + } + public static function paragraphsItemSubmit(array $form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement();