Skip to content

Commit 401cb6e

Browse files
scott graysonscott grayson
authored andcommitted
Add tags field to edit resource forms (EditFile, EditLink, EditFolder)
1 parent c18a95e commit 401cb6e

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

src/Resources/Pages/EditFile.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ public function form(\Filament\Schemas\Schema $schema): \Filament\Schemas\Schema
4343
->label('Description')
4444
->rows(3),
4545

46+
\Filament\Forms\Components\Select::make('tags')
47+
->label('Tags')
48+
->relationship('tags', 'name')
49+
->multiple()
50+
->searchable()
51+
->preload()
52+
->createOptionForm([
53+
\Filament\Forms\Components\TextInput::make('name')
54+
->required()
55+
->maxLength(255),
56+
])
57+
->createOptionUsing(function (array $data): int {
58+
$tag = \Tapp\FilamentLibrary\Models\LibraryItemTag::create([
59+
'name' => $data['name'],
60+
'slug' => \Illuminate\Support\Str::slug($data['name']),
61+
]);
62+
63+
return $tag->id;
64+
}),
65+
4666
\Filament\Forms\Components\Select::make('general_access')
4767
->label('General Access')
4868
->options(function () {

src/Resources/Pages/EditFolder.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ public function form(\Filament\Schemas\Schema $schema): \Filament\Schemas\Schema
2828
->label('Description')
2929
->rows(3),
3030

31+
\Filament\Forms\Components\Select::make('tags')
32+
->label('Tags')
33+
->relationship('tags', 'name')
34+
->multiple()
35+
->searchable()
36+
->preload()
37+
->createOptionForm([
38+
\Filament\Forms\Components\TextInput::make('name')
39+
->required()
40+
->maxLength(255),
41+
])
42+
->createOptionUsing(function (array $data): int {
43+
$tag = \Tapp\FilamentLibrary\Models\LibraryItemTag::create([
44+
'name' => $data['name'],
45+
'slug' => \Illuminate\Support\Str::slug($data['name']),
46+
]);
47+
48+
return $tag->id;
49+
}),
50+
3151
Select::make('general_access')
3252
->label('General Access')
3353
->options(function () {

src/Resources/Pages/EditLink.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ public function form(\Filament\Schemas\Schema $schema): \Filament\Schemas\Schema
3232
->label('Description')
3333
->rows(3),
3434

35+
\Filament\Forms\Components\Select::make('tags')
36+
->label('Tags')
37+
->relationship('tags', 'name')
38+
->multiple()
39+
->searchable()
40+
->preload()
41+
->createOptionForm([
42+
\Filament\Forms\Components\TextInput::make('name')
43+
->required()
44+
->maxLength(255),
45+
])
46+
->createOptionUsing(function (array $data): int {
47+
$tag = \Tapp\FilamentLibrary\Models\LibraryItemTag::create([
48+
'name' => $data['name'],
49+
'slug' => \Illuminate\Support\Str::slug($data['name']),
50+
]);
51+
52+
return $tag->id;
53+
}),
54+
3555
\Filament\Forms\Components\Select::make('general_access')
3656
->label('General Access')
3757
->options(function () {

0 commit comments

Comments
 (0)