From: Vincent Vanwaelscappel Date: Tue, 5 Oct 2021 10:03:58 +0000 (+0200) Subject: wip #4666 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=6eec26598ffb2fd86cbdfc53f68143fdb6f96481;p=cubist_cms-back.git wip #4666 @0.5 --- diff --git a/composer.json b/composer.json index e7075bf..f486c98 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "digitallyhappy/toggle-field-for-backpack": "^2.0", "calebporzio/parental": "^v0.11", "cache/filesystem-adapter": "^1.1", - "laravel/framework": "^v8.61" + "laravel/framework": "^v8.62" }, "require-dev": { diff --git a/src/app/Magic/Controllers/CubistMagicController.php b/src/app/Magic/Controllers/CubistMagicController.php index 89896e7..5d8f03c 100644 --- a/src/app/Magic/Controllers/CubistMagicController.php +++ b/src/app/Magic/Controllers/CubistMagicController.php @@ -94,6 +94,29 @@ class CubistMagicController extends CubistCrudController $this->updateFieldsFromModel($model); } + public function setupSaveActions($type) + { + + $instance = $this->getModelInstance(); + if ($instance instanceof CubistMagicAbstractModel) { + if ($this->_oneInstance) { + $this->crud->removeSaveAction('save_and_back'); + $this->crud->removeSaveAction('save_and_new'); + } + $instance->setupSaveActions($this, $type); + } + } + + public function setupCreateOperation() + { + $this->setupSaveActions('create'); + } + + public function setupUpdateOperation() + { + $this->setupSaveActions('update'); + } + public function updateFieldsFromModel($model = null) { if (null === $model) { @@ -233,7 +256,7 @@ class CubistMagicController extends CubistCrudController public function index() { if ($this->_oneInstance) { - return Redirect::to(backpack_url( $this->_routeURL . '/1/edit') ); + return Redirect::to(backpack_url($this->_routeURL . '/1/edit')); } return parent::index(); } diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index b633e09..79be77f 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -544,6 +544,14 @@ class CubistMagicAbstractModel extends Model implements HasMedia ->optimize(); } + /** + * @param $controller CubistMagicController + */ + public function setupSaveActions($controller, $type) + { + + } + public function getIdValue() { return $this->getKey(); diff --git a/src/app/Magic/Operations/CreateOperation.php b/src/app/Magic/Operations/CreateOperation.php index c8cee37..2d66e24 100644 --- a/src/app/Magic/Operations/CreateOperation.php +++ b/src/app/Magic/Operations/CreateOperation.php @@ -7,6 +7,7 @@ trait CreateOperation { use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation { store as _store; + setupCreateDefaults as _setupCreateDefaults; } public function store() @@ -17,4 +18,9 @@ trait CreateOperation } return $res; } + + protected function setupCreateDefaults() + { + $this->_setupCreateDefaults(); + } } diff --git a/src/app/Magic/Operations/UpdateOperation.php b/src/app/Magic/Operations/UpdateOperation.php index bdeadc8..1b07d96 100644 --- a/src/app/Magic/Operations/UpdateOperation.php +++ b/src/app/Magic/Operations/UpdateOperation.php @@ -7,6 +7,7 @@ trait UpdateOperation { use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation{ update as _update; + setupUpdateDefaults as _setupUpdateDefaults; } @@ -23,4 +24,9 @@ trait UpdateOperation } return $res; } + + protected function setupUpdateDefaults() + { + $this->_setupUpdateDefaults(); + } }