]> _ Git - cubist_cms-back.git/commitdiff
#2878
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 10 Jul 2019 10:01:09 +0000 (12:01 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 10 Jul 2019 10:01:09 +0000 (12:01 +0200)
src/CubistBackpackServiceProvider.php
src/app/Http/Controllers/CubistFrontController.php
src/app/Magic/Menu/Item.php
src/app/Magic/Models/CMSPage.php
src/app/Magic/PageData.php [new file with mode: 0644]
src/resources/config/cubist.php [new file with mode: 0644]

index c487552f442d32141d31f34fc01d535c9583540b..dce9a764c0a323dcc0c180d332ef9e53bea0c0c7 100644 (file)
@@ -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) {
index 8365161ca0e36adfc3a8ff13a83870d1991fbecb..7319b1c9fb68790f2f8960a9ac4bb8cafc9d7a8d 100644 (file)
@@ -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 <a href="' . url('') . '">homepage</a>.');
     }
+
+
 }
index fd4eb99b1f0d135c4a9e0b25a70486f121e96058..691681efd11870b877cbdd58289bfc434397a734 100644 (file)
@@ -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);
index 42b0f446bbffc457e454486b1a46050c0ff41fd3..1f496f8d07bcce231ec8e28f461425be2dc42e93 100644 (file)
@@ -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 (file)
index 0000000..c9d60da
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+
+
+namespace Cubist\Backpack\app\Magic;
+
+
+class PageData implements \ArrayAccess
+{
+    protected $_data = [];
+
+    public function __construct($data)
+    {
+        if (is_array($data)) {
+            $this->_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 (file)
index 0000000..e5bf797
--- /dev/null
@@ -0,0 +1,2 @@
+<?php
+return ['page_model' => '\App\Models\Page'];