You are here

public static function WidgetBase::addMoreSubmit in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Field/WidgetBase.php \Drupal\Core\Field\WidgetBase::addMoreSubmit()

Submission handler for the "Add another item" button.

File

core/lib/Drupal/Core/Field/WidgetBase.php, line 274
Contains \Drupal\Core\Field\WidgetBase.

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();
}