You are here

public function SwitchPageThemeSettingForm::removeElement in Switch Page Theme 8.3

Same name and namespace in other branches
  1. 8 src/Form/SwitchPageThemeSettingForm.php \Drupal\switch_page_theme\Form\SwitchPageThemeSettingForm::removeElement()
  2. 8.2 src/Form/SwitchPageThemeSettingForm.php \Drupal\switch_page_theme\Form\SwitchPageThemeSettingForm::removeElement()

Submit handler for the "Remove" button(s).

Remove the element from table and causes a form rebuild.

File

src/Form/SwitchPageThemeSettingForm.php, line 305

Class

SwitchPageThemeSettingForm
Configuration page for Switch page theme settings.

Namespace

Drupal\switch_page_theme\Form

Code

public function removeElement(array &$form, FormStateInterface $form_state) {

  // Get table.
  $spt_table = $form_state
    ->get('spt_table');

  // Get element to remove.
  $remove = key($form_state
    ->getValue('spt_table'));

  // Remove element.
  unset($spt_table[$remove]);

  // Set an empty element if no elements are left.
  if (empty($spt_table)) {
    array_push($spt_table, "");
  }
  $form_state
    ->set('spt_table', $spt_table);
  $form_state
    ->setRebuild();
}