You are here

public function DropDownLoginAdminForm::removeCallback in Drop Down Login 8

Submit handler for the "remove one" button.

Decrements the max counter and causes a form rebuild.

File

src/Form/DropDownLoginAdminForm.php, line 228

Class

DropDownLoginAdminForm
Class SettingsForm.

Namespace

Drupal\drop_down_login\Form

Code

public function removeCallback(array &$form, FormStateInterface $form_state) {
  $triggerdElement = $form_state
    ->getTriggeringElement();
  if (!empty($triggerdElement['#name'])) {
    $name = explode('_', $triggerdElement['#name']);
    $num_rows = $form_state
      ->get('num_rows');
    $pointer = array_search($name['2'], $num_rows);
    unset($num_rows[$pointer]);
    $form_state
      ->set('num_rows', $num_rows);
    if (empty($num_rows)) {
      $form_state
        ->set('empty_rows', 1);
    }
  }
  $form_state
    ->setRebuild();
}