]> _ Git - cubist_cms-back.git/commitdiff
wip #3439 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 27 Feb 2020 18:44:34 +0000 (19:44 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 27 Feb 2020 18:44:34 +0000 (19:44 +0100)
src/app/Console/Commands/GenerateCommand.php
src/app/Http/Controllers/CubistCrudController.php
src/app/Magic/Controllers/CubistMagicController.php
src/resources/cubistmagic/routes.stub

index 3c712f97ccbef7cc269d334f8f29e65b2c080b15..4191c8511a15b72e2d9dcef776e1afbb545491a3 100644 (file)
@@ -21,6 +21,11 @@ class GenerateCommand extends CubistCommand
      */
     protected $description = 'Generate Controllers, Requests, Routes, migrations according to magic';
 
+    /**
+     * @var array
+     */
+    protected $_routes = [];
+
 
     /**
      * Execute the console command.
@@ -44,6 +49,7 @@ class GenerateCommand extends CubistCommand
             mkdir($routesDir, 0777, true);
         }
         $stub = file_get_contents(Util::getStubPath() . '/routes.stub');
+        $stub = str_replace('_CUSTOM_', implode("\n    ", $this->_routes), $stub);
 
         file_put_contents($routesDir . '/custom.php', $stub);
     }
@@ -58,6 +64,8 @@ class GenerateCommand extends CubistCommand
 
         $route = $model->getOption('route', $model->getOption('name'));
         $controller = $model->getControllerClass();
+
+        $this->_routes[] = ' Route::crud(\'' . $route . '\', \'' . $controller . '\');';
     }
 }
 
index 09b6b328db1461aa07f3da173f4213f4c7ea9a9c..2cd3fd36acd895883ce4697d24014a1ea9014cd8 100644 (file)
@@ -11,18 +11,25 @@ class CubistCrudController extends CrudController
 {
     public function __construct()
     {
-        if (!$this->crud) {
+        if ($this->crud) {
+            return;
+        }
+
+        // call the setup function inside this closure to also have the request there
+        // this way, developers can use things stored in session (auth variables, etc)
+        $this->middleware(function ($request, $next) {
+            // make a new CrudPanel object, from the one stored in Laravel's service container
             $this->crud = app()->make(CubistCrudPanel::class);
+            // ensure crud has the latest request
+            $this->crud->setRequest($request);
+            $this->request = $request;
+            $this->setupDefaults();
+            $this->setup();
+            $this->setupConfigurationForCurrentOperation();
 
-            // call the setup function inside this closure to also have the request there
-            // this way, developers can use things stored in session (auth variables, etc)
-            $this->middleware(function ($request, $next) {
-                $this->request = $request;
-                $this->crud->request = $request;
-                $this->setup();
+            return $next($request);
+        });
 
-                return $next($request);
-            });
-        }
+        parent::__construct();
     }
 }
index 6852bf3ded3df87e5a2b91b875157576d2b7318f..8419ef18d3ef064c58a0dfba62344a4b6c85a14f 100644 (file)
@@ -30,7 +30,6 @@ use Illuminate\Support\Facades\Route;
 
 class CubistMagicController extends CubistCrudController
 {
-    use CrudTrait;
     use HandleAjaxMedia;
 
     use ListOperation;
@@ -50,11 +49,6 @@ class CubistMagicController extends CubistCrudController
     protected $_oneInstance;
     protected $_nested = false;
 
-    public function __construct()
-    {
-        parent::__construct();
-    }
-
     // Routes
 //Route::post($this->name . '/bulk-publish', [
 ////'as' => 'crud.' . $this->name . '.bulkPublish',
@@ -150,7 +144,7 @@ class CubistMagicController extends CubistCrudController
         }
 
 
-        $this->crud->setRoute(config('backpack.base.route_prefix') . '/' . $this->_routeURL);
+        $this->crud->setRoute(backpack_url($this->_routeURL));
         $this->crud->setEntityNameStrings($this->_singular, $this->_plural);
 
 
@@ -164,9 +158,6 @@ class CubistMagicController extends CubistCrudController
         $this->crud->addColumn(['name' => $model->getPrimaryKey(), 'type' => 'number', 'label' => "#", 'searchLogic' => 'text']);
 
         $this->updateFieldsFromModel($model);
-
-        $this->setupRoutes($this->_routeURL, $this->_routeURL, $this->_routeURL);
-
     }
 
     public function updateFieldsFromModel($model = null)
@@ -368,4 +359,20 @@ class CubistMagicController extends CubistCrudController
         $this->_forgetCache();
         parent::saveReorder();
     }
+
+    public function setupListOperation()
+    {
+        echo ":)";
+    }
+
+    public function setupCreateOperation()
+    {
+        echo ":)";
+    }
+
+    public function setupUpdateOperation()
+    {
+        echo ":)";
+    }
+
 }
index c2f7f550c3729e5ec4a5b71d7ac8a500e75f99c3..b6008f635b9c56d57f2c882c98e34c3e751303c3 100644 (file)
@@ -4,5 +4,5 @@ Route::group([
     'middleware' => ['web', config('backpack.base.middleware_key', 'admin')],
     'namespace'  => 'App\Http\Controllers\Admin',
 ], function () { // custom admin routes
-
+    _CUSTOM_
 });