]> _ Git - cubist_cms-back.git/commitdiff
#2843
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 2 Jul 2019 19:00:17 +0000 (21:00 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 2 Jul 2019 19:00:17 +0000 (21:00 +0200)
src/app/Magic/Models/CMSPage.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/app/Magic/Models/CubistMagicNestedModel.php

index 84b89b5602f4aef485e8dc1c42eb42351fee92a0..15df6c82a93e371092fddf30f07ade67f830ef41 100644 (file)
@@ -43,6 +43,12 @@ class CMSPage extends CubistMagicNestedModel
             'tab' => 'Informations principales',
         ]);
 
+        $this->addField(['name' => 'slug',
+            'label' => 'Slug (URL)',
+            'type' => 'Slug',
+            'tab' => 'Informations principales',
+        ]);
+
         $this->_common();
     }
 
index a80efbefa66e32b9bbb7a9396fded625c3e835c3..876f0ab26cd9c51e8a1539eae3eaf97aa84d8fe7 100644 (file)
@@ -9,9 +9,9 @@ use Cubist\Backpack\app\Magic\Controllers\CubistMagicController;
 use Cubist\Backpack\app\Magic\Fields\Field;
 use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
 use Cubist\Backpack\app\Magic\Util;
-use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
 use Backpack\CRUD\ModelTraits\SpatieTranslatable\Sluggable;
 use Backpack\CRUD\ModelTraits\SpatieTranslatable\SluggableScopeHelpers;
+use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
 use Cubist\Util\Json;
 use Doctrine\DBAL\Schema\Schema;
 use Doctrine\DBAL\Schema\Table;
@@ -25,9 +25,7 @@ use Venturecraft\Revisionable\RevisionableTrait;
 class CubistMagicAbstractModel extends Model implements HasMedia
 {
     use CrudTrait;
-    use Sluggable {
-        replicate as protected replicateSluggable;
-    }
+    use Sluggable;
     use SluggableScopeHelpers;
     use HasTranslations {
         update as protected updateTranslations;
@@ -343,11 +341,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         $table->addColumn('deleted_at', 'datetime', $options);
     }
 
-    public function replicate(array $except = null)
-    {
-        return $this->replicateSluggable($except);
-    }
-
     public function __call($method, $parameters)
     {
 
@@ -464,6 +457,13 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return $this->createTranslations($attributes);
     }
 
+    public function getSlugAttribute($value){
+        if(!$value){
+            return Str::slug($this->title);
+        }
+        return $value;
+    }
+
     /**
      * @param $controller CubistMagicController
      */
index 56eeb3c2c6dd7d503f1fd11edb7f58a537a89d6a..1110ce0966db318a765439d8248cb47ff61c623e 100644 (file)
@@ -27,4 +27,31 @@ class CubistMagicNestedModel extends CubistMagicModel
     {
         return 'CubistMagicNestedController';
     }
+
+
+    public static function getTree()
+    {
+        $all = self::orderBy('lft')->get();
+        $res = [];
+        self::_appendToTree($res, null, $all);
+
+        return $res;
+    }
+
+    /**
+     * @param array $tree
+     * @param $id
+     * @param self[] $all
+     */
+    public static function _appendToTree(&$tree, $id, $all)
+    {
+        foreach ($all as $e) {
+            if ($e->parent_id != $id) {
+                continue;
+            }
+            $item = ['element' => $e, 'children' => []];
+            self::_appendToTree($item['children'], $e->id, $all);
+            $tree[$e->name] = $item;
+        }
+    }
 }