public function SettingsForm::submitForm in Habitat 8
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides ConfigFormBase::submitForm
File
- habitat_ui/
src/ Form/ SettingsForm.php, line 78 - Contains \Drupal\habitat_ui\Form\SettingsForm.
Class
- SettingsForm
- Defines a form that configures habitat settings.
Namespace
Drupal\habitat_ui\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = \Drupal::configFactory()
->getEditable('habitat.settings');
$config
->set('habitat_variable', $form_state
->getValue('variable'));
$habitats = array_filter(array_map('trim', explode("\n", $form_state
->getValue('habitats'))));
$config
->set('habitat_habitats', $habitats);
$original_habitats = $config
->get('habitat_habitats');
foreach ($original_habitats as $original_habitat) {
if (in_array($original_habitat, $habitats)) {
$config
->set('habitat_install_' . $original_habitat, array_filter(array_map('trim', explode("\n", $form_state
->getValue('install_' . $original_habitat)))));
$config
->set('habitat_uninstall_' . $original_habitat, array_filter(array_map('trim', explode("\n", $form_state
->getValue('uninstall_' . $original_habitat)))));
}
else {
$config
->clear('habitat_install_' . $original_habitat);
$config
->clear('habitat_uninstall_' . $original_habitat);
}
}
$config
->save();
}