Skip to content

Commit 7a52901

Browse files
Merge pull request #6 from jonassiewertsen/add_documentation
Clean up and bug fixes
2 parents 04431cf + 111b54a commit 7a52901

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

src/Commands/Setup.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace Jonassiewertsen\Statamic\HowTo\Commands;
44

55
use Illuminate\Console\Command;
6+
use Jonassiewertsen\Statamic\HowTo\Helper\Documentation;
7+
use Jonassiewertsen\Statamic\HowTo\Helper\Video;
68
use Statamic\Facades\Collection;
79
use Statamic\Fields\Blueprint;
10+
use Statamic\Structures\CollectionStructure;
811

912
class Setup extends Command
1013
{
@@ -46,21 +49,22 @@ public function handle()
4649
}
4750

4851
private function createCollections() {
49-
Collection::make(config('howToAddon.collection.videos', 'how_to_addon_videos'))
50-
->entryBlueprints(config('howToAddon.blueprint.videos', 'how_to_addon_videos'))
52+
Collection::make(Video::collectionName())
53+
->entryBlueprints(Video::collectionName())
5154
->title('How to videos')
5255
->save();
5356

54-
Collection::make(config('howToAddon.collection.documentation', 'how_to_addon_documentation'))
55-
->entryBlueprints(config('howToAddon.blueprint.documentation', 'how_to_addon_documentation'))
57+
Collection::make(Documentation::collectionName())
58+
->entryBlueprints(Documentation::collectionName())
5659
->title('How to documentation')
60+
->structure((new CollectionStructure)->maxDepth(2))
5761
->save();
5862
}
5963

6064
protected function createBlueprints()
6165
{
6266
(new Blueprint)
63-
->setHandle(config('howToAddon.blueprint.videos', 'how_to_addon_videos'))
67+
->setHandle(Video::collectionName())
6468
->setContents([
6569
'title' => 'How to Video',
6670
'sections' => [
@@ -94,7 +98,7 @@ protected function createBlueprints()
9498
])->save();
9599

96100
(new Blueprint)
97-
->setHandle(config('howToAddon.blueprint.documentation', 'how_to_addon_documentation'))
101+
->setHandle(Documentation::collectionName())
98102
->setContents([
99103
'title' => 'How to documentation',
100104
'sections' => [
@@ -110,6 +114,7 @@ protected function createBlueprints()
110114
'localizable' => false,
111115
'listable' => 'hidden',
112116
'display' => 'Content',
117+
'validate' => 'required',
113118
]]
114119
]
115120
],
@@ -128,4 +133,4 @@ protected function createBlueprints()
128133
])->save();
129134

130135
}
131-
}
136+
}

src/Helper/Documentation.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public static function entryChildren($tree, $nav): LaravelCollection
3838
});
3939
}
4040

41+
/**
42+
* Fetch the belonging children for the navigation
43+
*/
44+
public static function exists(): bool
45+
{
46+
return Collection::handleExists(self::collectionName());
47+
}
48+
4149
/**
4250
* Return the entry title
4351
*/

src/Http/Controllers/VideosController.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
namespace Jonassiewertsen\Statamic\HowTo\Http\Controllers;
44

5-
use Statamic\Facades\Asset;
65
use Statamic\Facades\Entry;
76

87
class VideosController {
9-
public function index() {
8+
public function index()
9+
{
1010
$videos = Entry::whereCollection('how_to_addon_videos');
1111

1212
$videos = $this->sortByTitle($videos);
1313

1414
return view('howToAddon::videos.index', compact('videos'));
1515
}
1616

17-
public function show($slug) {
17+
public function show($slug)
18+
{
1819
$video = Entry::findBySlug($slug, config('howToAddon.blueprint.videos', 'how_to_addon_videos'));
1920

2021
// TODO: Should be replaced by Asset::findByPath later.
@@ -24,7 +25,8 @@ public function show($slug) {
2425
return view('howToAddon::videos.show', compact('video', 'url'));
2526
}
2627

27-
private function sortByTitle($videos) {
28+
private function sortByTitle($videos)
29+
{
2830
return collect($videos)->sortBy('title');
2931
}
30-
}
32+
}

src/ServiceProvider.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ private function createNavigation(): void
6666

6767
Nav::extend(function ($nav) {
6868

69-
Documentation::tree()->map(function ($tree) use ($nav) {
70-
return $nav->create(Documentation::entryTitle($tree['entry']))
71-
->route('howToAddon.documentation.show', Documentation::entrySlug($tree['entry']))
72-
->icon('drawer-file')
73-
->section('Documentation')
74-
->children(Documentation::entryChildren($tree, $nav));
75-
});
69+
if (Documentation::exists()) {
70+
Documentation::tree()->map(function ($tree) use ($nav) {
71+
return $nav->create(Documentation::entryTitle($tree['entry']))
72+
->route('howToAddon.documentation.show', Documentation::entrySlug($tree['entry']))
73+
->icon('drawer-file')
74+
->section('Documentation')
75+
->children(Documentation::entryChildren($tree, $nav));
76+
});
77+
}
7678

7779
// Only show the Manage button, if the permissions have been set
7880
if (Gate::allows('edit', Collection::findByHandle(Documentation::collectionName()))) {

0 commit comments

Comments
 (0)