From: Vincent Vanwaelscappel Date: Wed, 6 Sep 2023 17:37:58 +0000 (+0200) Subject: wip #6250 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=e826835b970492b7b0d47f65ed3d059da192562a;p=cubist_cms-back.git wip #6250 @1 --- diff --git a/src/app/Middleware/BunchRequest.php b/src/app/Middleware/BunchRequest.php index 4bb4b97..00e16b7 100644 --- a/src/app/Middleware/BunchRequest.php +++ b/src/app/Middleware/BunchRequest.php @@ -3,6 +3,7 @@ namespace Cubist\Backpack\Middleware; use Closure; +use Cubist\Util\Json; use Illuminate\Http\Request; use Illuminate\Support\Arr; @@ -14,6 +15,7 @@ class BunchRequest extends CubistMiddleware $appendComposite = []; $newBag = []; + $init = $request->all(); foreach ($request->all() as $field => $content) { $e = explode('___', $field); if (count($e) > 1) { @@ -25,6 +27,11 @@ class BunchRequest extends CubistMiddleware } Arr::set($appendComposite, $field, $content); } else { + if (is_string($content) && stristr($content, '___') && Json::isJson($content)) { + $data = json_decode($content, true); + $this->normalizeBunchInBunch($data); + $content = $data; + } $newBag[$field] = $content; } } @@ -34,4 +41,25 @@ class BunchRequest extends CubistMiddleware return $this->getResponse(); } + + protected function normalizeBunchInBunch(&$data) + { + foreach ($data as $k => $v) { + if (is_array($v)) { + $this->normalizeBunchInBunch($v); + } + if (stristr($k, '___')) { + $e = explode('___', $k); + $varname = $e[0]; + $sub = $e[1]; + if (!isset($data[$varname])) { + $data[$varname] = []; + } + $data[$varname][$sub] = $v; + unset($data[$k]); + } else { + $data[$k] = $v; + } + } + } }