ConfigForm: Remove empty sections

fixes #4939

(cherry picked from commit 4d0e42787a4fed81fd0ace1337ffca6ca42dcf96)
This commit is contained in:
Johannes Meyer 2022-11-02 15:34:01 +01:00
parent aa7767e0f5
commit 817380470a

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
*