ConfigForm: Remove empty sections

fixes #4939
This commit is contained in:
Johannes Meyer 2022-11-02 15:34:01 +01:00
parent 8cb0976c5b
commit 4d0e42787a

View File

@ -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
*