diff --git a/src/Plugin/Field/FieldWidget/ParagraphsWidget.php b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php index 1905b24..3a68896 100644 --- a/src/Plugin/Field/FieldWidget/ParagraphsWidget.php +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php @@ -956,6 +956,19 @@ class ParagraphsWidget extends WidgetBase { ], ]; + // Hidden field provided by "Modal" mode. Field is provided for additional + // integrations, where also position of addition can be specified. It should + // be used by sub-modules or other paragraphs integration. CSS class is used + // to support easier element selecting in JavaScript. + $element['add_modal_form_area']['add_more_delta'] = [ + '#type' => 'hidden', + '#attributes' => [ + 'class' => [ + 'paragraph-type-add-modal-delta', + ], + ], + ]; + $element['#attached']['library'][] = 'paragraphs/drupal.paragraphs.modal'; if ($this->isFeatureEnabled('add_above')) { $element['#attached']['library'][] = 'paragraphs/drupal.paragraphs.add_above_button'; @@ -1826,7 +1839,7 @@ class ParagraphsWidget extends WidgetBase { $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'] + ['add_more', 'add_modal_form_area', 'add_more_delta', '#value'] ); static::prepareDeltaPosition($submit['widget_state'], $form_state, $field_path, $add_more_delta);