diff --git a/application/forms/ConfigForm.php b/application/forms/ConfigForm.php index 9a93ca918..8b0c5f9c8 100644 --- a/application/forms/ConfigForm.php +++ b/application/forms/ConfigForm.php @@ -77,7 +77,11 @@ class ConfigForm extends Form } foreach ($sections as $section => $config) { - $this->config->setSection($section, $config); + if ($this->isEmptyConfig($config)) { + $this->config->removeSection($section); + } else { + $this->config->setSection($section, $config); + } } if ($this->save()) { @@ -146,6 +150,28 @@ class ConfigForm extends Form $config->saveIni(); } + /** + * Get whether the given config is empty or has only empty values + * + * @param array|Config $config + * + * @return bool + */ + protected function isEmptyConfig($config) + { + if ($config instanceof Config) { + $config = $config->toArray(); + } + + foreach ($config as $value) { + if ($value !== null) { + return false; + } + } + + return true; + } + /** * Transform all empty values of the given array to null *