Fixed fatal error in admin if POST request has data in it [#2074]

This commit is contained in:
Matias Griese
2021-02-18 15:33:38 +02:00
parent 1a2a2c52c9
commit 64e41b034e
3 changed files with 16 additions and 9 deletions

View File

@@ -1,3 +1,9 @@
# v1.10.5
## dd/mm/2021
1. [](#bugfix)
* Fixed fatal error in admin if POST request has `data` in it [#2074](https://github.com/getgrav/grav-plugin-admin/issues/2074)
# v1.10.4 # v1.10.4
## 02/17/2021 ## 02/17/2021

View File

@@ -269,7 +269,7 @@ class Admin
$name = $file->getBasename('.yaml'); $name = $file->getBasename('.yaml');
// Check that blueprint exists and is not hidden. // Check that blueprint exists and is not hidden.
$data = $admin->data('config/'. $name); $data = $admin->data('config/'. $name, null);
if (!is_callable([$data, 'blueprints'])) { if (!is_callable([$data, 'blueprints'])) {
continue; continue;
} }
@@ -838,12 +838,12 @@ class Admin
* Gets configuration data. * Gets configuration data.
* *
* @param string $type * @param string $type
* @param array $post * @param array|null $post
* *
* @return mixed * @return object
* @throws \RuntimeException * @throws \RuntimeException
*/ */
public function data($type, array $post = []) public function data($type, ?array $post = [])
{ {
static $data = []; static $data = [];
@@ -851,9 +851,11 @@ class Admin
return $data[$type]; return $data[$type];
} }
if (!$post) { if (null !== $post && !$post) {
$post = $this->grav['uri']->post(); $post = $this->grav['uri']->post()['data'] ?? null;
$post = $post['data'] ?? []; if (!is_array($post)) {
$post = [];
}
} }
// Check to see if a data type is plugin-provided, before looking into core ones // Check to see if a data type is plugin-provided, before looking into core ones

View File

@@ -2695,9 +2695,8 @@ class AdminController extends AdminBaseController
protected function prepareData(array $data) protected function prepareData(array $data)
{ {
$type = trim("{$this->view}/{$this->admin->route}", '/'); $type = trim("{$this->view}/{$this->admin->route}", '/');
$data = $this->admin->data($type, $data);
return $data; return $this->admin->data($type, $data);
} }
/** /**