Handle special case of media configuration (#638)

* Handle special case of media configuration

Since it's a list of dynamically generated entries, without parent, we
cannot merge in the post data with the defaults, or the defaults are
always saved, and we cannot remove existing fields

* Correctly handle reading and saving

* Improve implementation
This commit is contained in:
Flavio Copes
2016-06-02 20:21:35 +02:00
committed by Andy Miller
parent ebcd52803a
commit 45e9e77179

View File

@@ -328,8 +328,15 @@ class Admin
$type = preg_replace('|config/|', '', $type);
$blueprints = $this->blueprints("config/{$type}");
$config = $this->grav['config'];
$obj = new Data\Data($config->get($type, []), $blueprints);
if ($type === 'media' && count($post)) {
$obj = new Data\Data([], $blueprints); // saving
} else {
$obj = new Data\Data($config->get($type, []), $blueprints);
}
$obj->merge($post);
// FIXME: We shouldn't allow user to change configuration files in system folder!
$filename = $this->grav['locator']->findResource("config://{$type}.yaml")
?: $this->grav['locator']->findResource("config://{$type}.yaml", true, true);