public static function WidgetBase::addMoreSubmit

public static WidgetBase::addMoreSubmit(array $form, FormStateInterface $form_state)

Submission handler for the "Add another item" button.

File

core/lib/Drupal/Core/Field/WidgetBase.php, line 269

Class

WidgetBase
Base class for 'Field widget' plugin implementations.

Namespace

Drupal\Core\Field

Code

public static function addMoreSubmit(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, -1));
  $field_name = $element['#field_name'];
  $parents = $element['#field_parents'];

  // Increment the items count.
  $field_state = static::getWidgetState($parents, $field_name, $form_state);
  $field_state['items_count']++;
  static::setWidgetState($parents, $field_name, $form_state, $field_state);

  $form_state->setRebuild();
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Field!WidgetBase.php/function/WidgetBase::addMoreSubmit/8.1.x