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

index 2ea006d4a07b50d398984a551aa1d5c24adf4fa6..05efc8ce02cc4c3f5e51c5a54d114e62a08660d6 100644 (file)
@@ -6,5 +6,17 @@ use Backpack\CRUD\CrudPanel;
 
 class CubistCrudPanel extends CrudPanel
 {
+    public function hasField($name)
+    {
+        $lists = ['getCreateFields', 'getUpdateFields'];
 
+        foreach ($lists as $list) {
+            foreach ($this->$list(1) as $field) {
+                if ($field['name'] == $name) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
 }
index 790b35af1ecaba79b0721c44b5a3459e2a22d4a0..b8a0d50a0dfac997e0191455d84f5719f28be242 100644 (file)
@@ -58,10 +58,19 @@ trait CubistMagicControllerTrait
 
         $this->crud->addColumn(['name' => $model->getPrimaryKey(), 'type' => 'number', 'label' => "#", 'searchLogic' => 'text']);
 
+        $this->updateFieldsFromModel();
+
+    }
+
+    public function updateFieldsFromModel()
+    {
+        $model = $this->getModelInstance();
         foreach ($model->getFields() as $field) {
+            if ($this->crud->hasField($field->getAttribute('name'))) {
+                continue;
+            }
             $this->addField($field);
         }
-
     }
 
 
index 95a65ec88e41f64896c1e7fd87fff0b85655c56b..5d895a6c3a7e9bef4fec4b0f9067196d7c92f1ff 100644 (file)
@@ -3,6 +3,8 @@
 
 namespace Cubist\Backpack\app\Magic\Models;
 
+use Cubist\Backpack\app\Template\TemplateAbstract;
+
 class CMSPage extends CubistMagicModel
 {
     protected static $_templates = [];
@@ -92,20 +94,43 @@ class CMSPage extends CubistMagicModel
         ]);
     }
 
-    public function onBeforeEdit($controller, $id)
+    public function onBeforeCreate($controller)
     {
-
+        parent::onBeforeCreate($controller);
     }
 
-    public function onBeforeUpdate($controller, $request)
+    public function onBeforeEdit($controller, $id)
     {
-
+        parent::onBeforeEdit($controller, $id);
     }
 
     public function onBeforeStore($controller, $request)
     {
+        parent::onBeforeStore($controller, $request);
+    }
 
+    public function onBeforeUpdate($controller, $request)
+    {
+        parent::onBeforeUpdate($controller, $request);
     }
 
+    /**
+     * @param $template
+     * @throws \Exception
+     */
+    protected function useTemplate($template)
+    {
+        if (is_string($template)) {
+            $template = new $template();
+        }
+
+        $fields = $template->getFields();
+        if (!count($fields)) {
+            return;
+        }
+        foreach ($fields as $field) {
+            $this->addFakeField($field);
+        }
+    }
 
 }
index 3213ab16dc8dcecfacab83c21f5fd952dcf6241e..8a8338db2c58f19b75860a670448bd4035679d42 100644 (file)
@@ -468,10 +468,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return $this->{$this->getPrimaryKey()};
     }
 
-    protected function useTemplate($template)
-    {
-
-    }
 
     /**
      * @param $controller CubistMagicController
index ddb83eabed08917f2d4ddb172d0e87950e9de85a..cbadaf9939d7c76374aeee180e4d49198c573c1f 100644 (file)
@@ -2,61 +2,41 @@
 
 namespace Cubist\Backpack\app\Template;
 
-use Cubist\Backpack\app\Magic\BunchOfFields;
 use Illuminate\Support\Str;
 
 class TemplateAbstract
 {
-    use BunchOfFields;
 
     /**
      * @var TemplateAbstract[]
      */
     protected static $_templates = null;
 
-    protected function _seo()
-    {
-        $this->addField([
-            'name' => 'meta_title',
-            'label' => trans('backpack::pagemanager.meta_title'),
-            'type' => 'Text',
-            'hint' => trans('If empty, page title is used.') . ' ' . __('Recommended length: 60 chars'),
-            'tab' => 'Meta // SEO',
-        ]);
-        $this->addField([
-            'name' => 'meta_description',
-            'label' => trans('backpack::pagemanager.meta_description'),
-            'type' => 'Textarea',
-            'hint' => __('Recommended length: 160 chars'),
-            'tab' => 'Meta // SEO',
-        ]);
-        $this->addField([
-            'name' => 'robots',
-            'label' => __('Allow page index by search engines'),
-            'type' => 'Checkbox',
-            'default' => true,
-            'tab' => 'Meta // SEO',
-        ]);
-    }
+    protected $defaultFieldAttributes = ['translate' => true];
+
+    protected $_fields = [];
 
     public function init()
     {
-        $this->_common();
+
     }
 
-    protected function _common()
+    /**
+     * @param $attributes array
+     */
+    public function addField($attributes)
     {
-        $this->addField([
-            'name' => 'status',
-            'type' => 'SelectFromArray',
-            'default' => '0',
-            'label' => __('Status'),
-            'options' => ['0' => __('Offline'), '1' => __('Published')],
-            'tab' => 'Général',
-        ]);
-        $this->_seo();
+        $attributes = array_merge($this->defaultFieldAttributes, $attributes);
+        $this->_fields[$attributes['name']] = $attributes;
     }
 
+    /**
+     * @return array
+     */
+    public function getFields()
+    {
+        return $this->_fields;
+    }
 
     public function showInDropDown()
     {