Skip to content

Commit 4b1bd7f

Browse files
committed
Add new navigation class
1 parent 0ade8ea commit 4b1bd7f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Navigation/Navigation.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace KodiCMS\CMS\Navigation;
44

5+
use KodiComponents\Navigation\Contracts\PageInterface;
6+
57
class Navigation extends \KodiComponents\Navigation\Navigation
68
{
79

@@ -18,4 +20,28 @@ public function render()
1820
'pages' => $this->toArray(),
1921
])->render();
2022
}
23+
24+
/**
25+
* @param array $data
26+
*
27+
* @return PageInterface
28+
*/
29+
protected function createPageFromArray(array $data)
30+
{
31+
$page = app(PageInterface::class);
32+
33+
foreach ($data as $key => $value) {
34+
if ($key != 'children' and method_exists($page, $method = 'set'.ucfirst($key))) {
35+
$page->{$method}($value);
36+
}
37+
}
38+
39+
if (isset($data['children']) and is_array($data['children'])) {
40+
foreach ($data['children'] as $child) {
41+
$page->addPage($child);
42+
}
43+
}
44+
45+
return $page;
46+
}
2147
}

src/Providers/ModuleLoaderServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
use KodiCMS\CMS\CMS;
66
use Collective\Html\FormFacade;
77
use Collective\Html\HtmlFacade;
8-
use KodiCMS\CMS\Navigation\Navigation;
98
use KodiCMS\CMS\Navigation\Page;
109
use KodiCMS\Support\Facades\Wysiwyg;
1110
use KodiCMS\Support\Helpers\Profiler;
1211
use Illuminate\Foundation\AliasLoader;
12+
use KodiCMS\CMS\Navigation\Navigation;
1313
use KodiCMS\Support\Facades\KeysHelper;
1414
use KodiCMS\Assets\AssetsServiceProvider;
1515
use KodiCMS\Support\Loader\ModulesLoader;

0 commit comments

Comments
 (0)