You are here

public static function MultiValue::addMoreSubmit in SAML Authentication 8.3

Same name and namespace in other branches
  1. 4.x src/Element/MultiValue.php \Drupal\samlauth\Element\MultiValue::addMoreSubmit()

Handles the "Add another item" button AJAX request.

Parameters

array $form: The build form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

See also

\Drupal\Core\Field\WidgetBase::addMoreSubmit()

File

src/Element/MultiValue.php, line 365

Class

MultiValue
Provides a multi-value form element.

Namespace

Drupal\samlauth\Element

Code

public static function addMoreSubmit(array $form, FormStateInterface $form_state) : void {
  $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));
  $element_name = $element['#field_name'];
  $parents = $element['#parents'];

  // Increment the items count.
  $element_state = static::getElementState($parents, $element_name, $form_state);
  $element_state['items_count']++;
  static::setElementState($parents, $element_name, $form_state, $element_state);
  $form_state
    ->setRebuild();
}