public static function AssociativeArrayWidget::addMorePairsAjax in Map Widget 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.
File
- src/
Plugin/ Field/ FieldWidget/ AssociativeArrayWidget.php, line 184
Class
- AssociativeArrayWidget
- Plugin implementation of the 'map_item_widget' widget.
Namespace
Drupal\map_widget\Plugin\Field\FieldWidgetCode
public static function addMorePairsAjax(array $form, FormStateInterface $form_state) {
$button = $form_state
->getTriggeringElement();
// Go one level up in the form, and get this delta value.
$element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -1));
// Add a DIV around this element.
$element['#prefix'] = '<div class="ajax-new-content">' . (isset($element['#prefix']) ? $element['#prefix'] : '');
$element['#suffix'] = (isset($element['#suffix']) ? $element['#suffix'] : '') . '</div>';
return $element;
}