-@stop
\ No newline at end of file
+@stop
diff --git a/src/Commands/Setup.php b/src/Commands/Setup.php
index 8e0edfa..5d117bc 100644
--- a/src/Commands/Setup.php
+++ b/src/Commands/Setup.php
@@ -42,7 +42,7 @@ public function handle()
$this->createCollections();
$this->createBlueprints();
- $this->info('Everything as been setup for you. Cheers!');
+ $this->info('Everything has been setup for you. Cheers!');
}
private function createCollections() {
@@ -50,37 +50,82 @@ private function createCollections() {
->entryBlueprints(config('howToAddon.blueprint.videos', 'how_to_addon_videos'))
->title('How to videos')
->save();
+
+ Collection::make(config('howToAddon.collection.documentation', 'how_to_addon_documentation'))
+ ->entryBlueprints(config('howToAddon.blueprint.documentation', 'how_to_addon_documentation'))
+ ->title('How to documentation')
+ ->save();
}
protected function createBlueprints()
{
- $blueprint = new Blueprint;
+ (new Blueprint)
+ ->setHandle(config('howToAddon.blueprint.videos', 'how_to_addon_videos'))
+ ->setContents([
+ 'title' => 'How to Video',
+ 'sections' => [
+ 'main' => [
+ 'fields' => [
+ ['handle' => 'video', 'field' => [
+ 'type' => 'assets',
+ 'allow_upload' => true,
+ 'max_files' => 1,
+ 'validate' => 'required'
+ ]],
+ ['handle' => 'description', 'field' => [
+ 'character_limit' => 133,
+ 'type' => 'text',
+ 'display' => 'description',
+ ]]
+ ],
+ ],
+ 'sidebar' => [
+ 'fields' => [
+ ['handle' => 'slug', 'field' => [
+ 'type' => 'slug',
+ 'localizable' => false,
+ 'listable' => 'hidden',
+ 'display' => 'Slug',
+ 'validate' => 'required',
+ ]],
+ ],
+ ],
+ ]
+ ])->save();
- $blueprint->setHandle(config('howToAddon.blueprint.videos', 'how_to_addon_videos'))
- ->setContents([
- 'title' => 'Video',
- 'sections' => [
- 'main' => [
- 'fields' => [
- ['handle' => 'video', 'field' => [
- 'type' => 'assets',
- 'allow_upload' => true,
- 'max_files' => 1,
- 'validate' => 'required'
- ]],
- ['handle' => 'description', 'field' => [
- 'character_limit' => 133,
- 'type' => 'text',
- 'display' => 'description'
- ]]
- ],
- ],
- 'sidebar' => [
- 'fields' => [
- ['handle' => 'slug', 'field' => ['type' => 'slug']],
- ],
- ],
+ (new Blueprint)
+ ->setHandle(config('howToAddon.blueprint.documentation', 'how_to_addon_documentation'))
+ ->setContents([
+ 'title' => 'How to documentation',
+ 'sections' => [
+ 'main' => [
+ 'fields' => [
+ ['handle' => 'content', 'field' =>[
+ 'restrict' => false,
+ 'automatic_line_breaks' => true,
+ 'automatic_links' => false,
+ 'escape_markup' => false,
+ 'smartypants' => false,
+ 'type' => 'markdown',
+ 'localizable' => false,
+ 'listable' => 'hidden',
+ 'display' => 'Content',
+ ]]
]
- ])->save();
+ ],
+ 'sidebar' => [
+ 'fields' => [
+ ['handle' => 'slug', 'field' => [
+ 'type' => 'slug',
+ 'localizable' => false,
+ 'listable' => 'hidden',
+ 'display' => 'Slug',
+ 'validate' => 'required',
+ ]],
+ ],
+ ],
+ ]
+ ])->save();
+
}
}
\ No newline at end of file
diff --git a/src/Helper/Documentation.php b/src/Helper/Documentation.php
new file mode 100644
index 0000000..b48e2e9
--- /dev/null
+++ b/src/Helper/Documentation.php
@@ -0,0 +1,64 @@
+structure()
+ ->in(Site::selected()->handle())->tree();
+
+ return collect($tree);
+ }
+
+ /**
+ * Fetch the belonging children for the navigation
+ */
+ public static function entryChildren($tree, $nav): LaravelCollection
+ {
+ if (! isset($tree['children'])) {
+ return collect();
+ }
+
+ return collect($tree['children'])->map(function ($child) use ($nav, $tree) {
+ return $nav->item(self::entryTitle($child['entry']))
+ ->route('howToAddon.documentation.child.show', [
+ 'parent' => Documentation::entrySlug($tree['entry']),
+ 'slug' => Documentation::entrySlug($child['entry'])
+ ]);
+ });
+ }
+
+ /**
+ * Return the entry title
+ */
+ public static function entryTitle($entry): string
+ {
+ return Entry::find($entry)->title;
+ }
+
+ /**
+ * Return the slug
+ */
+ public static function entrySlug($entry): string
+ {
+ return Entry::find($entry)->slug();
+ }
+
+ /**
+ * Return the documentation collection name
+ */
+ public static function collectionName(): string
+ {
+ return config('howToAddon.collection.documentation', 'how_to_addon_documentation');
+ }
+}
diff --git a/src/Helper/Video.php b/src/Helper/Video.php
new file mode 100644
index 0000000..71f218d
--- /dev/null
+++ b/src/Helper/Video.php
@@ -0,0 +1,14 @@
+app->runningInConsole()) {
$this->publishes([
- __DIR__.'/../resources/lang' => resource_path('lang/vendor/jonassiewertsen/howToAddon/'),
+ __DIR__ . '/../resources/lang' => resource_path('lang/vendor/jonassiewertsen/howToAddon/'),
], 'How To Addon lang file');
$this->publishes([
@@ -49,28 +51,45 @@ private function createNavigation(): void
$nav->create(__('howToAddon::menu.videos'))
->icon('assets')
->section('How To')
- ->route('howToAddon.index');
+ ->route('howToAddon.videos.index');
// Only show the Manage button, if the permissions have been set
- if (Gate::allows('edit', Collection::findByHandle(config('howToAddon.collection.videos', 'how_to_addon_videos')))) {
+ if (Gate::allows('edit', Collection::findByHandle(Video::collectionName()))) {
$nav->create(__('howToAddon::menu.manage'))
->icon('settings-slider')
->section('How To')
->route('collections.show', [
- 'collection' => $this->videoCollectionName(),
+ 'collection' => Video::collectionName(),
+ ]);
+ }
+ });
+
+ Nav::extend(function ($nav) {
+
+ Documentation::tree()->map(function ($tree) use ($nav) {
+ return $nav->create(Documentation::entryTitle($tree['entry']))
+ ->route('howToAddon.documentation.show', Documentation::entrySlug($tree['entry']))
+ ->icon('drawer-file')
+ ->section('Documentation')
+ ->children(Documentation::entryChildren($tree, $nav));
+ });
+
+ // Only show the Manage button, if the permissions have been set
+ if (Gate::allows('edit', Collection::findByHandle(Documentation::collectionName()))) {
+ $nav->create(__('howToAddon::menu.manage'))
+ ->icon('settings-slider')
+ ->section('Documentation')
+ ->route('collections.show', [
+ 'collection' => Documentation::collectionName(),
]);
}
});
}
- private function loadCommands(array $commands) {
+ private function loadCommands(array $commands)
+ {
if ($this->app->runningInConsole()) {
$this->commands($commands);
}
}
-
- private function videoCollectionName()
- {
- return config('howToAddon.collection.videos', 'how_to_addon_videos');
- }
}
diff --git a/src/routes/cp.php b/src/routes/cp.php
index 077c1fa..763fcfa 100644
--- a/src/routes/cp.php
+++ b/src/routes/cp.php
@@ -1,5 +1,9 @@
name('howToAddon.index');
-Route::get('/how-to-addon/create', 'VideosController@create')->name('howToAddon.create');
-Route::get('/how-to-addon/video/{video}', 'VideosController@show')->name('howToAddon.show');
\ No newline at end of file
+/** Videos */
+Route::get('/how-to/videos', 'VideosController@index')->name('howToAddon.videos.index');
+Route::get('/how-to/video/{video}', 'VideosController@show')->name('howToAddon.videos.show');
+
+/** Documentation */
+Route::get('/how-to/documentation/{slug}', 'DocumentationController@show')->name('howToAddon.documentation.show');
+Route::get('/how-to/documentation/{parent}/{slug}', 'DocumentationController@showChild')->name('howToAddon.documentation.child.show');