From b7db1260e6327c33c45778afc57609441053c2b1 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 12 Jul 2019 15:07:00 +0200 Subject: [PATCH] #2757 --- composer.json | 3 +- .../Http/Controllers/CubistPageController.php | 5 ++-- src/app/Magic/BunchOfFields.php | 3 ++ src/app/Magic/Menu/Item.php | 28 +++++++++++++++++++ src/app/Magic/Models/CMSPage.php | 2 -- .../Magic/Models/CubistMagicAbstractModel.php | 15 ++++++++-- 6 files changed, 47 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 5a6c5c6..24deb9e 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,8 @@ "gaspertrix/laravel-backpack-dropzone-field": "^1.0", "cviebrock/eloquent-sluggable": "^4.8", "cocur/slugify": "^3.2", - "lavary/laravel-menu": "^1.7" + "lavary/laravel-menu": "^1.7", + "graham-campbell/markdown": "^11.0" }, "require-dev": { "filp/whoops": "^2.3", diff --git a/src/app/Http/Controllers/CubistPageController.php b/src/app/Http/Controllers/CubistPageController.php index 5ea2754..6d48186 100644 --- a/src/app/Http/Controllers/CubistPageController.php +++ b/src/app/Http/Controllers/CubistPageController.php @@ -5,7 +5,6 @@ namespace Cubist\Backpack\app\Http\Controllers; use Cubist\Backpack\app\Magic\Menu\Menu; use Cubist\Backpack\app\Magic\Models\CMSPage; use Illuminate\Support\Str; -use Illuminate\View\View; class CubistPageController extends CubistFrontController { @@ -27,7 +26,7 @@ class CubistPageController extends CubistFrontController // Page templates can modify/inject data before it is passed to the view $page->getUsedTemplate()->setData($this->data); - return view('pages.' . $page->template, $this->data); + return view('pages.' . $page->getAttributeValue('template'), $this->data); } public function catchall($main = '', $subs = '') @@ -38,7 +37,7 @@ class CubistPageController extends CubistFrontController $path = 'home'; } $nav = Menu::getNavigation(); - $item = $nav->findOneByHref($path); + $item = $nav->findItemWithURL($path); if (null === $item) { $this->_404(); } diff --git a/src/app/Magic/BunchOfFields.php b/src/app/Magic/BunchOfFields.php index d7b053b..6bfc00c 100644 --- a/src/app/Magic/BunchOfFields.php +++ b/src/app/Magic/BunchOfFields.php @@ -47,6 +47,9 @@ trait BunchOfFields public function addFakeField(array $attributes) { $attributes['fake'] = true; + if (!isset($attributes['store_in'])) { + $attributes['store_in'] = 'extras'; + } return $this->addField($attributes); } diff --git a/src/app/Magic/Menu/Item.php b/src/app/Magic/Menu/Item.php index b9859c7..de32d59 100644 --- a/src/app/Magic/Menu/Item.php +++ b/src/app/Magic/Menu/Item.php @@ -144,6 +144,33 @@ class Item return $this->findOneBy('href', $href); } + public function findAllBy($param, $search) + { + $res = []; + if ($this->get($param) == $search) { + $res[] = $this; + } + foreach ($this->getChildren() as $child) { + $res = array_merge($res, $child->findAllBy($param, $search)); + } + + return $res; + } + + public function findItemWithURL($href) + { + foreach ($this->findAllBy('href', $href) as $item) { + if (!($item instanceof PageItem)) { + return $item; + } + /** @var $item PageItem */ + if (stristr($item->getPage()->template, 'redirection')) { + continue; + } + return $item; + } + } + /** * @return string */ @@ -236,6 +263,7 @@ class Item return $href; } + /** * @param string $href */ diff --git a/src/app/Magic/Models/CMSPage.php b/src/app/Magic/Models/CMSPage.php index db46adc..365752a 100644 --- a/src/app/Magic/Models/CMSPage.php +++ b/src/app/Magic/Models/CMSPage.php @@ -4,8 +4,6 @@ namespace Cubist\Backpack\app\Magic\Models; use Cubist\Backpack\app\Magic\Controllers\CubistMagicController; -use Cubist\Backpack\app\Template\Navigation; -use Cubist\Backpack\app\Template\Redirection; use Cubist\Backpack\app\Template\TemplateAbstract; use Cubist\Util\Json; use Doctrine\DBAL\Schema\Schema; diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 5c587f6..dc0e906 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -17,7 +17,6 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Table; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; -use mysql_xdevapi\Exception; use Spatie\MediaLibrary\HasMedia\HasMedia; use Spatie\MediaLibrary\HasMedia\HasMediaTrait; use Spatie\MediaLibrary\Models\Media; @@ -326,7 +325,7 @@ class CubistMagicAbstractModel extends Model implements HasMedia $this->fakeColumns = array_unique($this->fakeColumns); foreach ($this->fakeColumns as $fakeColumn) { - $table->addColumn($fakeColumn, 'text'); + $table->addColumn($fakeColumn, 'text', ['notnull' => false]); } if ($this->timestamps) { @@ -454,7 +453,17 @@ class CubistMagicAbstractModel extends Model implements HasMedia protected function _prepareData($attributes) { - return $attributes; + $res = []; + foreach ($attributes as $k => $attribute) { + if (stristr($k, '___')) { + continue; + } + if (stristr($k, 'bunchmultiple_')) { + continue; + } + $res[$k] = $attribute; + } + return $res; } public function update(array $attributes = [], array $options = []) -- 2.39.5