From: Vincent Vanwaelscappel Date: Thu, 4 Jul 2019 09:59:37 +0000 (+0200) Subject: #2843 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=34515b69866c73c8d215ae119a1b7a15a77262e9;p=cubist_cms-back.git #2843 --- diff --git a/composer.json b/composer.json index e0b5592..09c2cec 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "venturecraft/revisionable": "^1.30", "gaspertrix/laravel-backpack-dropzone-field": "^1.0", "cviebrock/eloquent-sluggable": "^4.8", - "cocur/slugify": "^3.2" + "cocur/slugify": "^3.2", + "lavary/laravel-menu": "^1.7" }, "require-dev": { "filp/whoops": "^2.3", diff --git a/src/app/Magic/CubistMenu.php b/src/app/Magic/CubistMenu.php new file mode 100644 index 0000000..351bde0 --- /dev/null +++ b/src/app/Magic/CubistMenu.php @@ -0,0 +1,99 @@ + $main) { + $nav_items = []; + foreach ($main['children'] as $name => $item) { + $submenus = null; + + $links = []; + + foreach ($item['children'] as $key => $child) { + $links[$child['element']->title] = $child['element']->slug; + } + + if (count($links) > 0) { + $submenus = [['links' => $links]]; + } + + $s = ['url' => $item['element']->slug]; + if (null !== $submenus) { + $s['submenus'] = $submenus; + } + + $nav_items[$item['element']->title] = $s; + } + + \Menu::make($mainKey, function ($menu) use ($nav_items) { + + foreach ($nav_items as $nav_label => $nav_item) { + + $parent = $menu->add($nav_label, $nav_item['url']); + + // Handle items with submenus + if (isset($nav_item['submenus'])) { + + foreach ($nav_item['submenus'] as $submenu_data) { + + // Create an empty sub-element that will serve as a wrapper for the submenu(s) + $wrapper = $parent->raw('')->attr(['class' => 'nav-submenu-wrapper']); + + // Some submenus have a title element + if (isset($submenu_data['title'])) { + $wrapper->raw($submenu_data['title'])->attr(['class' => 'nav-submenu-title']); + } + + foreach ($submenu_data['links'] as $label => $url) { + $wrapper->add($label, $url); + } + } + } + + } + + }); + } + + + if ($mainKey == '#main') { + // Also make a menu for the breadcrumbs - this one is simpler and doesn't have the submenu headings + \Menu::make('breadcrumbs', function ($menu) use ($nav_items) { + + // Start with home link + $menu = $menu->add('Home', ''); + + foreach ($nav_items as $nav_label => $nav_item) { + + $parent = $menu->add($nav_label, $nav_item['url']); + + // Handle items with submenus + if (isset($nav_item['submenus'])) { + + foreach ($nav_item['submenus'] as $submenu_data) { + foreach ($submenu_data['links'] as $label => $url) { + $parent->add($label, $url); + } + } + } + } + }); + } + } +} diff --git a/src/app/Magic/Models/CMSPage.php b/src/app/Magic/Models/CMSPage.php index e48bb42..bdaf96c 100644 --- a/src/app/Magic/Models/CMSPage.php +++ b/src/app/Magic/Models/CMSPage.php @@ -20,6 +20,11 @@ class CMSPage extends CubistMagicNestedModel protected $defaultFieldAttributes = ['translatable' => true]; + public static function boot() + { + parent::boot(); + } + public function setFields() { parent::setFields(); @@ -163,5 +168,9 @@ class CMSPage extends CubistMagicNestedModel return parent::update($attributes, $options); } + public static function getMenu(){ + + } + }