From f3a1a883bb6c2d4d6384edb2a1ffee6a6d6fe948 Mon Sep 17 00:00:00 2001 From: Jonas Siewertsen Date: Sun, 3 May 2020 12:37:32 +0200 Subject: [PATCH 1/5] Clean up video controller --- src/Http/Controllers/VideosController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Http/Controllers/VideosController.php b/src/Http/Controllers/VideosController.php index b353b3b..a3e3c74 100644 --- a/src/Http/Controllers/VideosController.php +++ b/src/Http/Controllers/VideosController.php @@ -2,11 +2,11 @@ namespace Jonassiewertsen\Statamic\HowTo\Http\Controllers; -use Statamic\Facades\Asset; use Statamic\Facades\Entry; class VideosController { - public function index() { + public function index() + { $videos = Entry::whereCollection('how_to_addon_videos'); $videos = $this->sortByTitle($videos); @@ -14,7 +14,8 @@ public function index() { return view('howToAddon::videos.index', compact('videos')); } - public function show($slug) { + public function show($slug) + { $video = Entry::findBySlug($slug, config('howToAddon.blueprint.videos', 'how_to_addon_videos')); // TODO: Should be replaced by Asset::findByPath later. @@ -24,7 +25,8 @@ public function show($slug) { return view('howToAddon::videos.show', compact('video', 'url')); } - private function sortByTitle($videos) { + private function sortByTitle($videos) + { return collect($videos)->sortBy('title'); } -} \ No newline at end of file +} From cb9fee3266037b5510bcad8657deda88ce739aad Mon Sep 17 00:00:00 2001 From: Jonas Siewertsen Date: Sun, 3 May 2020 13:10:40 +0200 Subject: [PATCH 2/5] Refactor setup command --- src/Commands/Setup.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Commands/Setup.php b/src/Commands/Setup.php index 5d117bc..755a4e6 100644 --- a/src/Commands/Setup.php +++ b/src/Commands/Setup.php @@ -3,6 +3,8 @@ namespace Jonassiewertsen\Statamic\HowTo\Commands; use Illuminate\Console\Command; +use Jonassiewertsen\Statamic\HowTo\Helper\Documentation; +use Jonassiewertsen\Statamic\HowTo\Helper\Video; use Statamic\Facades\Collection; use Statamic\Fields\Blueprint; @@ -46,13 +48,13 @@ public function handle() } private function createCollections() { - Collection::make(config('howToAddon.collection.videos', 'how_to_addon_videos')) - ->entryBlueprints(config('howToAddon.blueprint.videos', 'how_to_addon_videos')) + Collection::make(Video::collectionName()) + ->entryBlueprints(Video::collectionName()) ->title('How to videos') ->save(); - Collection::make(config('howToAddon.collection.documentation', 'how_to_addon_documentation')) - ->entryBlueprints(config('howToAddon.blueprint.documentation', 'how_to_addon_documentation')) + Collection::make(Documentation::collectionName()) + ->entryBlueprints(Documentation::collectionName()) ->title('How to documentation') ->save(); } @@ -60,7 +62,7 @@ private function createCollections() { protected function createBlueprints() { (new Blueprint) - ->setHandle(config('howToAddon.blueprint.videos', 'how_to_addon_videos')) + ->setHandle(Video::collectionName()) ->setContents([ 'title' => 'How to Video', 'sections' => [ @@ -94,7 +96,7 @@ protected function createBlueprints() ])->save(); (new Blueprint) - ->setHandle(config('howToAddon.blueprint.documentation', 'how_to_addon_documentation')) + ->setHandle(Documentation::collectionName()) ->setContents([ 'title' => 'How to documentation', 'sections' => [ @@ -128,4 +130,4 @@ protected function createBlueprints() ])->save(); } -} \ No newline at end of file +} From 180212835114b8918905703f3d175b61433a66da Mon Sep 17 00:00:00 2001 From: Jonas Siewertsen Date: Tue, 5 May 2020 19:58:25 +0200 Subject: [PATCH 3/5] A strcutured collection will be created automatically --- src/Commands/Setup.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Commands/Setup.php b/src/Commands/Setup.php index 755a4e6..5cbcac2 100644 --- a/src/Commands/Setup.php +++ b/src/Commands/Setup.php @@ -7,6 +7,7 @@ use Jonassiewertsen\Statamic\HowTo\Helper\Video; use Statamic\Facades\Collection; use Statamic\Fields\Blueprint; +use Statamic\Structures\CollectionStructure; class Setup extends Command { @@ -56,6 +57,7 @@ private function createCollections() { Collection::make(Documentation::collectionName()) ->entryBlueprints(Documentation::collectionName()) ->title('How to documentation') + ->structure((new CollectionStructure)->maxDepth(2)) ->save(); } From 3ef80d7a99d6cc40789cb0ba131fff9a496e8a92 Mon Sep 17 00:00:00 2001 From: Jonas Siewertsen Date: Tue, 5 May 2020 19:58:59 +0200 Subject: [PATCH 4/5] Hide documentation menu in cp when the collection has not been created --- src/Helper/Documentation.php | 8 ++++++++ src/ServiceProvider.php | 16 +++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Helper/Documentation.php b/src/Helper/Documentation.php index b48e2e9..6dc580b 100644 --- a/src/Helper/Documentation.php +++ b/src/Helper/Documentation.php @@ -38,6 +38,14 @@ public static function entryChildren($tree, $nav): LaravelCollection }); } + /** + * Fetch the belonging children for the navigation + */ + public static function exists(): bool + { + return Collection::handleExists(self::collectionName()); + } + /** * Return the entry title */ diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 69df748..e7363da 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -66,13 +66,15 @@ private function createNavigation(): void 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)); - }); + if (Documentation::exists()) { + 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()))) { From 111b54abb0417d5cf5ea3cf8b929f6b8796cbd31 Mon Sep 17 00:00:00 2001 From: Jonas Siewertsen Date: Tue, 5 May 2020 20:00:18 +0200 Subject: [PATCH 5/5] The content field for entries is now required --- src/Commands/Setup.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Commands/Setup.php b/src/Commands/Setup.php index 5cbcac2..2ab32ce 100644 --- a/src/Commands/Setup.php +++ b/src/Commands/Setup.php @@ -114,6 +114,7 @@ protected function createBlueprints() 'localizable' => false, 'listable' => 'hidden', 'display' => 'Content', + 'validate' => 'required', ]] ] ],