From 7f881ee628326af387ea1ce77bb0004b0ba31631 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 10 Jul 2019 12:01:09 +0200 Subject: [PATCH] #2878 --- src/CubistBackpackServiceProvider.php | 3 + .../Controllers/CubistFrontController.php | 19 +++++ src/app/Magic/Menu/Item.php | 3 +- src/app/Magic/Models/CMSPage.php | 9 +++ src/app/Magic/PageData.php | 81 +++++++++++++++++++ src/resources/config/cubist.php | 2 + 6 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/app/Magic/PageData.php create mode 100644 src/resources/config/cubist.php diff --git a/src/CubistBackpackServiceProvider.php b/src/CubistBackpackServiceProvider.php index c487552..dce9a76 100644 --- a/src/CubistBackpackServiceProvider.php +++ b/src/CubistBackpackServiceProvider.php @@ -27,10 +27,13 @@ class CubistBackpackServiceProvider extends ServiceProvider */ public function boot() { + $resourcesDir = __DIR__ . '/../resources'; + $this->loadTranslationsFrom(realpath(__DIR__ . '/resources/lang'), self::NAMESPACE); foreach (glob(__DIR__ . '/routes/cubist/backpack/*.php') as $filename) { $this->loadRoutesFrom($filename); } + $this->publishes([$resourcesDir . '/config/cubist.php' => config_path('cubist.php')], 'config'); $this->loadViewsFrom(realpath(__DIR__ . '/resources/views'), self::NAMESPACE); Blade::directive('vendor_asset', function ($path) { diff --git a/src/app/Http/Controllers/CubistFrontController.php b/src/app/Http/Controllers/CubistFrontController.php index 8365161..7319b1c 100644 --- a/src/app/Http/Controllers/CubistFrontController.php +++ b/src/app/Http/Controllers/CubistFrontController.php @@ -3,6 +3,8 @@ namespace Cubist\Backpack\app\Http\Controllers; +use App\Models\Page; +use Cubist\Backpack\app\Magic\Models\CMSPage; use Cubist\Backpack\app\Magic\Models\Settings; use Illuminate\Routing\Controller as BaseController; @@ -15,8 +17,25 @@ class CubistFrontController extends BaseController $this->data['global'] = Settings::find(1); } + public function index($slug = 'home') + { + $class = CMSPage::getPageClass(); + $page = $class::findBySlug($slug); + + if (!$page) { + $this->_404(); + } + + $this->data['title'] = $page->title; + $this->data['page'] = $page->withFakes()->getDecodedAttributes(); + + return view('pages.' . $page->template, $this->data); + } + protected function _404() { abort(404, 'Please go back to our homepage.'); } + + } diff --git a/src/app/Magic/Menu/Item.php b/src/app/Magic/Menu/Item.php index fd4eb99..691681e 100644 --- a/src/app/Magic/Menu/Item.php +++ b/src/app/Magic/Menu/Item.php @@ -36,8 +36,9 @@ class Item public function initFromDatabase($id = '#root') { + $class = CMSPage::getPageClass(); /** @var $all CMSPage[] */ - $all = CMSPage::orderBy('lft')->get(); + $all = $class::orderBy('lft')->get(); $this->setId('#root'); $this->setName($id); diff --git a/src/app/Magic/Models/CMSPage.php b/src/app/Magic/Models/CMSPage.php index 42b0f44..1f496f8 100644 --- a/src/app/Magic/Models/CMSPage.php +++ b/src/app/Magic/Models/CMSPage.php @@ -233,4 +233,13 @@ class CMSPage extends CubistMagicNestedModel { return $this->_usedTemplate instanceof Redirection; } + + public static function getPageClass(){ + $class = CMSPage::class; + $config = config('cubist.page_model', 'Cubist\Backpack\app\Magic\Models\CMSPage'); + if (class_exists($config)) { + $class = $config; + } + return $class; + } } diff --git a/src/app/Magic/PageData.php b/src/app/Magic/PageData.php new file mode 100644 index 0000000..c9d60da --- /dev/null +++ b/src/app/Magic/PageData.php @@ -0,0 +1,81 @@ +_data = $data; + return; + } + if (is_object($data)) { + foreach ($data as $k => $v) { + $this->set($k, $v); + } + } + } + + public function set($offset, $value) + { + $this->_data[$offset] = $value; + } + + public function exists($offset) + { + return isset($this->_data[$offset]) && null !== $this->_data[$offset]; + } + + public function unset($offset) + { + unset($this->_data[$offset]); + } + + public function get($offset, $default = null) + { + if (!$this->exists($offset)) { + return $default; + } + return $this->_data[$offset]; + } + + public function offsetSet($offset, $value) + { + $this->set($offset, $value); + } + + public function offsetExists($offset) + { + return $this->exists($offset); + } + + public function offsetUnset($offset) + { + return $this->unset($offset); + } + + public function offsetGet($offset) + { + return $this->get($offset); + } + + public function __get($name) + { + return $this->get($name); + } + + public function __set($name, $value) + { + return $this->set($name, $value); + } + + public function __unset($name) + { + $this->unset($name); + } +} diff --git a/src/resources/config/cubist.php b/src/resources/config/cubist.php new file mode 100644 index 0000000..e5bf797 --- /dev/null +++ b/src/resources/config/cubist.php @@ -0,0 +1,2 @@ + '\App\Models\Page']; -- 2.39.5