mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 00:04:04 +02:00
ConfigForm: Remove empty sections
fixes #4939 (cherry picked from commit 4d0e42787a4fed81fd0ace1337ffca6ca42dcf96)
This commit is contained in:
parent
aa7767e0f5
commit
817380470a
@ -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
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user