diff --git a/src/Exceptions/BlueprintNotFoundException.php b/src/Exceptions/BlueprintNotFoundException.php new file mode 100644 index 0000000000..c781a17e50 --- /dev/null +++ b/src/Exceptions/BlueprintNotFoundException.php @@ -0,0 +1,50 @@ +blueprintHandle = $blueprintHandle; + $this->namespace = $namespace; + } + + public function getSolution(): Solution + { + $description = ($suggestedBlueprint = $this->getSuggestedBlueprint()) + ? "Did you mean `$suggestedBlueprint`?" + : 'Are you sure the blueprint exists?'; + + return BaseSolution::create("The {$this->blueprintHandle} blueprint was not found.") + ->setSolutionDescription($description) + ->setDocumentationLinks([ + 'Read the blueprints guide' => Statamic::docsUrl('/blueprints'), + ]); + } + + protected function getSuggestedBlueprint() + { + if (! $this->namespace) { + return null; + } + + return StringComparator::findClosestMatch( + Blueprint::in($this->namespace)->map->handle()->values()->all(), + $this->blueprintHandle + ); + } +} diff --git a/src/Http/Controllers/CP/Collections/EntriesController.php b/src/Http/Controllers/CP/Collections/EntriesController.php index 540dd81ce0..6f583f1443 100644 --- a/src/Http/Controllers/CP/Collections/EntriesController.php +++ b/src/Http/Controllers/CP/Collections/EntriesController.php @@ -6,6 +6,7 @@ use Illuminate\Validation\ValidationException; use Statamic\Contracts\Entries\Entry as EntryContract; use Statamic\CP\Breadcrumbs; +use Statamic\Exceptions\BlueprintNotFoundException; use Statamic\Facades\Asset; use Statamic\Facades\Entry; use Statamic\Facades\Site; @@ -76,6 +77,10 @@ public function edit(Request $request, $collection, $entry) $blueprint = $entry->blueprint(); + if (! $blueprint) { + throw new BlueprintNotFoundException($entry->value('blueprint'), 'collections/'.$collection->handle()); + } + if (User::current()->cant('edit-other-authors-entries', [EntryContract::class, $collection, $blueprint])) { $blueprint->ensureFieldHasConfig('author', ['read_only' => true]); }