]> _ Git - cubist_cms-back.git/commitdiff
wip #6250 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 6 Sep 2023 17:37:58 +0000 (19:37 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 6 Sep 2023 17:37:58 +0000 (19:37 +0200)
src/app/Middleware/BunchRequest.php

index 4bb4b972b5687a5c44eb4cf11bc0b03a8b4d99f5..00e16b78c0385b69f4fedd8870367747581c0862 100644 (file)
@@ -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;
+            }
+        }
+    }
 }