public static function ParagraphsWidget::addMoreAjax in Paragraphs 8
Ajax callback for the "Add another item" button.
This returns the new page content to replace the page content made obsolete by the form submission.
Overrides WidgetBase::addMoreAjax
File
- src/
Plugin/ Field/ FieldWidget/ ParagraphsWidget.php, line 1706
Class
- ParagraphsWidget
- Plugin implementation of the 'entity_reference_revisions paragraphs' widget.
Namespace
Drupal\paragraphs\Plugin\Field\FieldWidgetCode
public static function addMoreAjax(array $form, FormStateInterface $form_state) {
$submit = ParagraphsWidget::getSubmitElementInfo($form, $form_state);
$element = $submit['element'];
// Add a DIV around the delta receiving the Ajax effect.
$delta = $submit['element']['#max_delta'];
$element[$delta]['#prefix'] = '<div class="ajax-new-content">' . (isset($element[$delta]['#prefix']) ? $element[$delta]['#prefix'] : '');
$element[$delta]['#suffix'] = (isset($element[$delta]['#suffix']) ? $element[$delta]['#suffix'] : '') . '</div>';
// Clear the Add more delta.
NestedArray::setValue($element, [
'add_more',
'add_more_delta',
'#value',
], '');
return $element;
}