Skip to content

Commit 56e4243

Browse files
[6.x] Fix "Create Entry" button on collection widget (#13082)
* Fix "Create Entry" button on collection widget * formatting * nitpick --------- Co-authored-by: Jason Varga <[email protected]>
1 parent 54bdedf commit 56e4243

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Widgets/Collection.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
use Statamic\CP\Column;
77
use Statamic\Facades\Collection as CollectionAPI;
88
use Statamic\Facades\Scope;
9+
use Statamic\Facades\Site;
910
use Statamic\Facades\User;
1011

12+
use function Statamic\trans as __;
13+
1114
class Collection extends Widget
1215
{
1316
public function component()
@@ -28,7 +31,16 @@ public function component()
2831

2932
[$sortColumn, $sortDirection] = $this->parseSort($collection);
3033

34+
$blueprints = $collection
35+
->entryBlueprints()
36+
->reject->hidden()
37+
->map(fn ($blueprint) => [
38+
'handle' => $blueprint->handle(),
39+
'title' => __($blueprint->title()),
40+
])->values();
41+
3142
$blueprint = $collection->entryBlueprint();
43+
3244
$columns = $blueprint
3345
->columns()
3446
->put('status', Column::make('status')
@@ -52,7 +64,10 @@ public function component()
5264
'initialPerPage' => $this->config('limit', 5),
5365
'canCreate' => User::current()->can('create', [EntryContract::class, $collection]) && $collection->hasVisibleEntryBlueprint(),
5466
'createLabel' => $collection->createLabel(),
55-
'blueprints' => $collection->entryBlueprints()->reject->hidden()->values(),
67+
'blueprints' => $blueprints->map(fn ($blueprint) => [
68+
...$blueprint,
69+
'createEntryUrl' => cp_route('collections.entries.create', [$collection->handle(), Site::selected(), 'blueprint' => $blueprint['handle']]),
70+
])->all(),
5671
'listingUrl' => cp_route('collections.show', $collection),
5772
]);
5873
}

0 commit comments

Comments
 (0)