public function SlideGroupBaseForm::removeCallback in Drupal Slider 8
Same name and namespace in other branches
- 8.2 src/Form/SlideGroupBaseForm.php \Drupal\drupal_slider\Form\SlideGroupBaseForm::removeCallback()
Submit handler for the "remove one" button.
Decrements the max counter and causes a form rebuild.
File
- src/
Form/ SlideGroupBaseForm.php, line 136
Class
- SlideGroupBaseForm
- Class SlideGroupBaseForm.
Namespace
Drupal\drupal_slider\FormCode
public function removeCallback(array &$form, FormStateInterface $form_state) {
$name_field = $form_state
->get('num_names');
if ($name_field > 1) {
$remove_button = $name_field - 1;
$form_state
->set('num_names', $remove_button);
}
// Since our buildForm() method relies on the value of 'num_names' to
// generate 'name' form elements, we have to tell the form to rebuild. If we
// don't do this, the form builder will not call buildForm().
$form_state
->setRebuild();
}