mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-03 03:46:30 +01:00
Fixed deleting list field options completely, didn't save changes [#2056]
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
1. [](#bugfix)
|
1. [](#bugfix)
|
||||||
* Fixed case-sensitive `accept` in `filepicker` field
|
* Fixed case-sensitive `accept` in `filepicker` field
|
||||||
* Fixed HTML Entities in titles [#2028]
|
* Fixed HTML Entities in titles [#2028]
|
||||||
|
* Fixed deleting list field options completely, didn't save changes [#2056](https://github.com/getgrav/grav-plugin-admin/issues/2056)
|
||||||
|
|
||||||
# v1.10.3
|
# v1.10.3
|
||||||
## 02/01/2021
|
## 02/01/2021
|
||||||
|
|||||||
@@ -835,28 +835,30 @@ class Admin
|
|||||||
$file = CompiledYamlFile::instance($filename);
|
$file = CompiledYamlFile::instance($filename);
|
||||||
|
|
||||||
if (preg_match('|plugins/|', $type)) {
|
if (preg_match('|plugins/|', $type)) {
|
||||||
/** @var Plugins $plugins */
|
$obj = Plugins::get(preg_replace('|plugins/|', '', $type));
|
||||||
$plugins = $this->grav['plugins'];
|
if (null === $obj) {
|
||||||
$obj = $plugins->get(preg_replace('|plugins/|', '', $type));
|
|
||||||
|
|
||||||
if (!$obj) {
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$obj->merge($post);
|
if ($post) {
|
||||||
|
$obj = $this->mergePost($obj, $post);
|
||||||
|
}
|
||||||
|
|
||||||
$obj->file($file);
|
$obj->file($file);
|
||||||
|
|
||||||
$data[$type] = $obj;
|
$data[$type] = $obj;
|
||||||
} elseif (preg_match('|themes/|', $type)) {
|
} elseif (preg_match('|themes/|', $type)) {
|
||||||
/** @var Themes $themes */
|
/** @var Themes $themes */
|
||||||
$themes = $this->grav['themes'];
|
$themes = $this->grav['themes'];
|
||||||
$obj = $themes->get(preg_replace('|themes/|', '', $type));
|
$obj = $themes->get(preg_replace('|themes/|', '', $type));
|
||||||
|
if (null === $obj) {
|
||||||
if (!$obj) {
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$obj->merge($post);
|
if ($post) {
|
||||||
|
$obj = $this->mergePost($obj, $post);
|
||||||
|
}
|
||||||
|
|
||||||
$obj->file($file);
|
$obj->file($file);
|
||||||
|
|
||||||
$data[$type] = $obj;
|
$data[$type] = $obj;
|
||||||
@@ -871,9 +873,12 @@ class Admin
|
|||||||
} elseif (preg_match('|config/|', $type)) {
|
} elseif (preg_match('|config/|', $type)) {
|
||||||
$type = preg_replace('|config/|', '', $type);
|
$type = preg_replace('|config/|', '', $type);
|
||||||
$blueprints = $this->blueprints("config/{$type}");
|
$blueprints = $this->blueprints("config/{$type}");
|
||||||
$config = $this->grav['config'];
|
|
||||||
$obj = new Data\Data($config->get($type, []), $blueprints);
|
$config = $this->grav['config'];
|
||||||
$obj->merge($post);
|
$obj = new Data\Data($config->get($type, []), $blueprints);
|
||||||
|
if ($post) {
|
||||||
|
$obj = $this->mergePost($obj, $post);
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: We shouldn't allow user to change configuration files in system folder!
|
// FIXME: We shouldn't allow user to change configuration files in system folder!
|
||||||
$filename = $this->grav['locator']->findResource("config://{$type}.yaml")
|
$filename = $this->grav['locator']->findResource("config://{$type}.yaml")
|
||||||
@@ -912,6 +917,22 @@ class Admin
|
|||||||
return $data[$type];
|
return $data[$type];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function mergePost(Data\Data $object, array $post)
|
||||||
|
{
|
||||||
|
$object->merge($post);
|
||||||
|
|
||||||
|
$blueprint = $object->blueprints();
|
||||||
|
$data = $blueprint->flattenData($post, true);
|
||||||
|
|
||||||
|
foreach ($data as $key => $val) {
|
||||||
|
if ($val === null) {
|
||||||
|
$object->set($key, $val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean user form post and remove extra stuff that may be passed along
|
* Clean user form post and remove extra stuff that may be passed along
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user