public static function AssociativeArrayWidget::addMorePairsSubmit in Map Widget 8
Submission handler for the "Add another item" button.
File
- src/
Plugin/ Field/ FieldWidget/ AssociativeArrayWidget.php, line 158
Class
- AssociativeArrayWidget
- Plugin implementation of the 'map_item_widget' widget.
Namespace
Drupal\map_widget\Plugin\Field\FieldWidgetCode
public static function addMorePairsSubmit(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));
$field_name = $element['#field_name'];
$parents = $element['#field_parents'];
$delta = $element['#delta'];
// Increment the associative item count.
$field_state = static::getWidgetState($parents, $field_name, $form_state);
$field_state['map_assoc_count'][$delta]++;
static::setWidgetState($parents, $field_name, $form_state, $field_state);
$form_state
->setRebuild();
}