diff --git a/CHANGELOG.md b/CHANGELOG.md index 95cafc1b..6dc8361b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ## 02/17/2021 diff --git a/classes/plugin/Admin.php b/classes/plugin/Admin.php index 4e6af151..eda72374 100644 --- a/classes/plugin/Admin.php +++ b/classes/plugin/Admin.php @@ -269,7 +269,7 @@ class Admin $name = $file->getBasename('.yaml'); // Check that blueprint exists and is not hidden. - $data = $admin->data('config/'. $name); + $data = $admin->data('config/'. $name, null); if (!is_callable([$data, 'blueprints'])) { continue; } @@ -838,12 +838,12 @@ class Admin * Gets configuration data. * * @param string $type - * @param array $post + * @param array|null $post * - * @return mixed + * @return object * @throws \RuntimeException */ - public function data($type, array $post = []) + public function data($type, ?array $post = []) { static $data = []; @@ -851,9 +851,11 @@ class Admin return $data[$type]; } - if (!$post) { - $post = $this->grav['uri']->post(); - $post = $post['data'] ?? []; + if (null !== $post && !$post) { + $post = $this->grav['uri']->post()['data'] ?? null; + if (!is_array($post)) { + $post = []; + } } // Check to see if a data type is plugin-provided, before looking into core ones diff --git a/classes/plugin/AdminController.php b/classes/plugin/AdminController.php index 1ec7e003..a2b74ee3 100644 --- a/classes/plugin/AdminController.php +++ b/classes/plugin/AdminController.php @@ -2695,9 +2695,8 @@ class AdminController extends AdminBaseController protected function prepareData(array $data) { $type = trim("{$this->view}/{$this->admin->route}", '/'); - $data = $this->admin->data($type, $data); - return $data; + return $this->admin->data($type, $data); } /**