From: Vincent Vanwaelscappel Date: Thu, 20 Jun 2019 16:16:57 +0000 (+0200) Subject: #2843 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=6809706e562d52b3e3dfa444a2dcd5799839570b;p=cubist_cms-back.git #2843 --- diff --git a/src/app/Magic/Controllers/CubistMagicControllerTrait.php b/src/app/Magic/Controllers/CubistMagicControllerTrait.php index b8a0d50..40196c3 100644 --- a/src/app/Magic/Controllers/CubistMagicControllerTrait.php +++ b/src/app/Magic/Controllers/CubistMagicControllerTrait.php @@ -62,9 +62,11 @@ trait CubistMagicControllerTrait } - public function updateFieldsFromModel() + public function updateFieldsFromModel($model = null) { - $model = $this->getModelInstance(); + if (null === $model) { + $model=$this->getModelInstance(); + } foreach ($model->getFields() as $field) { if ($this->crud->hasField($field->getAttribute('name'))) { continue; diff --git a/src/app/Magic/Models/CMSPage.php b/src/app/Magic/Models/CMSPage.php index e8f0f80..2f02c1a 100644 --- a/src/app/Magic/Models/CMSPage.php +++ b/src/app/Magic/Models/CMSPage.php @@ -3,6 +3,7 @@ namespace Cubist\Backpack\app\Magic\Models; +use Cubist\Backpack\app\Magic\Controllers\CubistMagicController; use Cubist\Backpack\app\Template\TemplateAbstract; class CMSPage extends CubistMagicModel @@ -94,9 +95,13 @@ class CMSPage extends CubistMagicModel ]); } + /** + * @param \Cubist\Backpack\app\Magic\Controllers\CubistMagicController $controller + * @throws \Exception + */ public function onBeforeCreate($controller) { - $this->useTemplate(request('template')); + $this->useTemplate(request('template'), $controller); parent::onBeforeCreate($controller); } @@ -108,27 +113,28 @@ class CMSPage extends CubistMagicModel $entry = self::findOrFail($id); $template = $entry->template; } - $this->useTemplate($template); + $this->useTemplate($template, $controller); parent::onBeforeEdit($controller, $id); } public function onBeforeStore($controller, $request) { - $this->useTemplate(\Request::input('template')); + $this->useTemplate(\Request::input('template'), $controller); parent::onBeforeStore($controller, $request); } public function onBeforeUpdate($controller, $request) { - $this->useTemplate(\Request::input('template')); + $this->useTemplate(\Request::input('template'), $controller); parent::onBeforeUpdate($controller, $request); } /** * @param $template TemplateAbstract + * @param $controller CubistMagicController * @throws \Exception */ - protected function useTemplate($template) + protected function useTemplate($template, $controller) { if (is_string($template)) { $template = TemplateAbstract::getTemplateIntanceByName($template); @@ -144,6 +150,8 @@ class CMSPage extends CubistMagicModel foreach ($fields as $field) { $this->addFakeField($field); } + + $controller->updateFieldsFromModel(); } }