From: Vincent Vanwaelscappel Date: Thu, 20 Jun 2019 15:58:40 +0000 (+0200) Subject: #2843 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2c25573df82d1944bd3d3582da6e469e5f68e55f;p=cubist_cms-back.git #2843 --- diff --git a/src/app/CubistCrudPanel.php b/src/app/CubistCrudPanel.php index 2ea006d..05efc8c 100644 --- a/src/app/CubistCrudPanel.php +++ b/src/app/CubistCrudPanel.php @@ -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; + } } diff --git a/src/app/Magic/Controllers/CubistMagicControllerTrait.php b/src/app/Magic/Controllers/CubistMagicControllerTrait.php index 790b35a..b8a0d50 100644 --- a/src/app/Magic/Controllers/CubistMagicControllerTrait.php +++ b/src/app/Magic/Controllers/CubistMagicControllerTrait.php @@ -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); } - } diff --git a/src/app/Magic/Models/CMSPage.php b/src/app/Magic/Models/CMSPage.php index 95a65ec..5d895a6 100644 --- a/src/app/Magic/Models/CMSPage.php +++ b/src/app/Magic/Models/CMSPage.php @@ -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); + } + } } diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 3213ab1..8a8338d 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -468,10 +468,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia return $this->{$this->getPrimaryKey()}; } - protected function useTemplate($template) - { - - } /** * @param $controller CubistMagicController diff --git a/src/app/Template/TemplateAbstract.php b/src/app/Template/TemplateAbstract.php index ddb83ea..cbadaf9 100644 --- a/src/app/Template/TemplateAbstract.php +++ b/src/app/Template/TemplateAbstract.php @@ -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() {