Skip to content

Commit

Permalink
Throw an exception if collection not found
Browse files Browse the repository at this point in the history
Fixes #1788
  • Loading branch information
duncanmcclean committed Sep 14, 2020
1 parent 3cc0e9a commit 44a1f99
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Fieldtypes/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Statamic\Fieldtypes;

use Statamic\Exceptions\CollectionNotFoundException;
use Statamic\Facades\Collection;
use Statamic\Facades\Entry;
use Statamic\Facades\Scope;
Expand Down Expand Up @@ -149,8 +150,13 @@ protected function getCreatables()

$collections = $this->getConfiguredCollections();

return collect($collections)->flatMap(function ($collection) use ($collections) {
$collection = Collection::findByHandle($collection);
return collect($collections)->flatMap(function ($collectionHandle) use ($collections) {
$collection = Collection::findByHandle($collectionHandle);

if (! $collection) {
throw new CollectionNotFoundException($collectionHandle);
}

$blueprints = $collection->entryBlueprints();

return $blueprints->map(function ($blueprint) use ($collection, $collections, $blueprints) {
Expand Down

2 comments on commit 44a1f99

@edalzell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the throw_if helper?

@duncanmcclean
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the throw_if helper?

Never even knew that existed, changed to use it now.

Please sign in to comment.