You are here

public static function ComponentSectionForm::addItemSubmit in Module Builder 8.3

Submission handler for the "Add another item" buttons.

File

src/Form/ComponentSectionForm.php, line 625

Class

ComponentSectionForm
Generic form for entering a section of data for a component.

Namespace

Drupal\module_builder\Form

Code

public static function addItemSubmit(array $form, FormStateInterface $form_state) {
  $button = $form_state
    ->getTriggeringElement();

  // Get the data item, using the address set in the button.
  $data = $form_state
    ->get('data');
  $data_item = $data
    ->getItem($button['#data_address']);

  // Add a new delta item.
  $data_item
    ->createItem();
  $form_state
    ->set('data', $data);
  $form_state
    ->setRebuild();
}