]> _ Git - cubist_cms-back.git/commitdiff
#2843
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 20 Jun 2019 15:29:59 +0000 (17:29 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 20 Jun 2019 15:29:59 +0000 (17:29 +0200)
src/app/Magic/Controllers/CubistMagicControllerTrait.php
src/app/Magic/Models/CMSPage.php
src/app/Magic/Models/CubistMagicAbstractModel.php

index 9c64cfe662d9019939753a3ee00cbcbc5dff970f..cde0494be7c3e52dc232ef6daed1d697571869cf 100644 (file)
@@ -106,6 +106,7 @@ trait CubistMagicControllerTrait
     public function store(CubistMagicStoreRequest $request)
     {
         $request = $this->_prepareCRUDData($request);
+        $this->getModelInstance()->onBeforeStore($this, $request);
 
         // your additional operations before save here
         $redirect_location = parent::storeCrud($request);
@@ -121,6 +122,7 @@ trait CubistMagicControllerTrait
     public function update(CubistMagicUpdateRequest $request)
     {
         $request = $this->_prepareCRUDData($request);
+        $this->getModelInstance()->onBeforeUpdate($this, $request);
 
         // your additional operations before save here
         $redirect_location = parent::updateCrud($request);
@@ -129,5 +131,9 @@ trait CubistMagicControllerTrait
         return $redirect_location;
     }
 
-
+    public function edit($id)
+    {
+        $this->getModelInstance()->onBeforeEdit($this, $id);
+        return parent::edit($id);
+    }
 }
index 586e52d4acf2bde5168bb7c4143c08a52b9bcb3d..37cdaa1f7f716ddced05392ebc3bc4eca54b66c1 100644 (file)
@@ -58,6 +58,12 @@ class CMSPage extends CubistMagicModel
 
     protected function _seo()
     {
+        $this->addField(['name' => 'slug',
+            'type' => 'Slug',
+            'label' => 'Slug (URL)',
+            'tab' => 'SEO // Meta',
+        ]);
+
         $this->addFakeField([
             'name' => 'meta_title',
             'label' => trans('backpack::pagemanager.meta_title'),
@@ -67,12 +73,6 @@ class CMSPage extends CubistMagicModel
             'store_in' => 'seo',
         ]);
 
-        $this->addField(['name' => 'slug',
-            'type' => 'Slug',
-            'label' => 'Slug (URL)',
-            'tab' => 'SEO // Meta',
-        ]);
-
         $this->addFakeField([
             'name' => 'meta_description',
             'label' => trans('backpack::pagemanager.meta_description'),
@@ -81,7 +81,7 @@ class CMSPage extends CubistMagicModel
             'tab' => 'SEO // Meta',
             'store_in' => 'seo',
         ]);
-        
+
         $this->addFakeField([
             'name' => 'robots',
             'label' => __('Allow page index by search engines'),
index d27cbfae25d987dd917820e48a3741f498a2dfd8..a780d739700890cd93965bc6990676899fa98e77 100644 (file)
@@ -68,6 +68,12 @@ class CubistMagicAbstractModel extends Model implements HasMedia
      */
     protected $_relationships = [];
 
+
+    /**
+     * @var array
+     */
+    protected $varSetBeforeOperations = [];
+
     public static function boot()
     {
         parent::boot();
@@ -224,6 +230,9 @@ class CubistMagicAbstractModel extends Model implements HasMedia
             if ($field->getAttribute('cast', false) !== false) {
                 $this->casts[$field->getAttribute('name')] = $field->getAttribute('cast');
             }
+            if ($field->getAttribute('set_before_operation', false) !== false) {
+                $this->varSetBeforeOperations[] = $field->getAttribute('name');
+            }
         }
 
 
@@ -270,7 +279,8 @@ class CubistMagicAbstractModel extends Model implements HasMedia
             'MODELNAMESPACE' => get_class($this),
             'EXTENDS' => $this->_getBaseController(),
             'CLONABLE' => $this->clonable ? 'true' : 'false',
-            'BULK' => $this->getOption('bulk', true) ? 'true' : 'false'
+            'BULK' => $this->getOption('bulk', true) ? 'true' : 'false',
+            'VARSETBEFOREOPERATION' => var_export($this->varSetBeforeOperations, true),
         ];
 
         $res = file_get_contents($stub);
@@ -456,5 +466,18 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return $this->{$this->getPrimaryKey()};
     }
 
+    public function onBeforeEdit($controller, $id)
+    {
+
+    }
+
+    public function onBeforeUpdate($controller, $request)
+    {
+
+    }
+
+    public function onBeforeStore($controller, $request)
+    {
 
+    }
 }