Skip to content

Commit 3aed5dd

Browse files
committed
Add backstage fields
1 parent 78ae31b commit 3aed5dd

6 files changed

Lines changed: 70 additions & 28 deletions

File tree

composer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
],
2222
"require": {
2323
"php": "^8.1",
24+
"backstage/fields": "*",
2425
"filament/filament": "^3.0",
2526
"spatie/laravel-package-tools": "^1.15.0",
2627
"spatie/laravel-permission": "*"
@@ -77,5 +78,11 @@
7778
}
7879
},
7980
"minimum-stability": "dev",
80-
"prefer-stable": true
81+
"prefer-stable": true,
82+
"repositories": {
83+
"backstage/fields": {
84+
"type": "vcs",
85+
"url": "git@github.com:backstagephp/fields.git"
86+
}
87+
}
8188
}

src/Concerns/HasBackstageManagement.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Backstage\UserManagement\Concerns;
66
use Illuminate\Auth\Passwords\CanResetPassword;
77
use Illuminate\Notifications\Notifiable;
8+
use Vormkracht10\Fields\Concerns\HasFields;
89

910
trait HasBackstageManagement
1011
{
@@ -15,4 +16,6 @@ trait HasBackstageManagement
1516
// Illuminate contracts:
1617
use Notifiable;
1718
use CanResetPassword;
19+
20+
use HasFields;
1821
}

src/Resources/UserResource.php

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Filament\Tables\Table;
1515
use Illuminate\Support\Facades\Hash;
1616
use Illuminate\Validation\Rules\Password;
17+
use Vormkracht10\Fields\Filament\RelationManagers\FieldsRelationManager;
1718

1819
class UserResource extends Resource
1920
{
@@ -27,27 +28,33 @@ public static function getModel(): string
2728
public static function form(Form $form): Form
2829
{
2930
return $form
30-
->schema([
31-
Forms\Components\TextInput::make('name')
32-
->label(__('Name'))
33-
->required()
34-
->maxLength(255),
35-
Forms\Components\TextInput::make('email')
36-
->label(__('Email'))
37-
->email()
38-
->required()
39-
->maxLength(255),
40-
41-
Forms\Components\TextInput::make('password')
42-
->password()
43-
->label(__('Password'))
44-
->revealable(Filament::arePasswordsRevealable())
45-
->rule(Password::default())
46-
->autocomplete('new-password')
47-
->dehydrated(fn($state): bool => filled($state))
48-
->dehydrateStateUsing(fn($state): string => Hash::make($state))
49-
->live(debounce: 500),
50-
]);
31+
->schema(function ($livewire) {
32+
$livewire = $livewire;
33+
34+
$formFields = $livewire->getFormFields();
35+
36+
return array_merge([
37+
Forms\Components\TextInput::make('name')
38+
->label(__('Name'))
39+
->required()
40+
->maxLength(255),
41+
Forms\Components\TextInput::make('email')
42+
->label(__('Email'))
43+
->email()
44+
->required()
45+
->maxLength(255),
46+
47+
Forms\Components\TextInput::make('password')
48+
->password()
49+
->label(__('Password'))
50+
->revealable(Filament::arePasswordsRevealable())
51+
->rule(Password::default())
52+
->autocomplete('new-password')
53+
->dehydrated(fn($state): bool => filled($state))
54+
->dehydrateStateUsing(fn($state): string => Hash::make($state))
55+
->live(debounce: 500),
56+
], $formFields);
57+
});
5158
}
5259

5360
public static function table(Table $table): Table
@@ -95,7 +102,7 @@ public static function table(Table $table): Table
95102
public static function getRelations(): array
96103
{
97104
return [
98-
//
105+
FieldsRelationManager::class
99106
];
100107
}
101108

src/Resources/UserResource/Pages/CreateUser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44

55
use Backstage\UserManagement\Resources\UserResource;
66
use Filament\Resources\Pages\CreateRecord;
7+
use Vormkracht10\Fields\Concerns\CanMapDynamicFields;
78

89
class CreateUser extends CreateRecord
910
{
11+
use CanMapDynamicFields;
12+
1013
protected static string $resource = UserResource::class;
14+
15+
public function getFormFields()
16+
{
17+
return $this->resolveFormFields();
18+
}
1119
}

src/Resources/UserResource/Pages/EditUser.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
use Backstage\UserManagement\Resources\UserResource;
66
use Filament\Actions;
77
use Filament\Resources\Pages\EditRecord;
8+
use Vormkracht10\Fields\Concerns\CanMapDynamicFields;
89

910
class EditUser extends EditRecord
1011
{
12+
use CanMapDynamicFields;
13+
1114
protected static string $resource = UserResource::class;
1215

1316
protected function getHeaderActions(): array
@@ -17,4 +20,10 @@ protected function getHeaderActions(): array
1720
Actions\DeleteAction::make(),
1821
];
1922
}
23+
24+
25+
public function getFormFields()
26+
{
27+
return $this->resolveFormFields();
28+
}
2029
}

src/Resources/UserResource/Pages/ViewUser.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
namespace Backstage\UserManagement\Resources\UserResource\Pages;
44

5-
use Backstage\UserManagement\Resources\UserResource;
65
use Filament\Actions;
76
use Filament\Facades\Filament;
8-
use Filament\Notifications\Auth\ResetPassword;
9-
use Filament\Notifications\Auth\VerifyEmail;
7+
use Illuminate\Support\HtmlString;
8+
use Illuminate\Support\Facades\Blade;
109
use Filament\Resources\Pages\ViewRecord;
1110
use Illuminate\Contracts\Support\Htmlable;
12-
use Illuminate\Support\Facades\Blade;
13-
use Illuminate\Support\HtmlString;
11+
use Filament\Notifications\Auth\VerifyEmail;
12+
use Filament\Notifications\Auth\ResetPassword;
13+
use Backstage\UserManagement\Resources\UserResource;
14+
use Vormkracht10\Fields\Concerns\CanMapDynamicFields;
1415

1516
class ViewUser extends ViewRecord
1617
{
18+
use CanMapDynamicFields;
19+
1720
protected static string $resource = UserResource::class;
1821

1922
protected function getHeaderActions(): array
@@ -88,4 +91,9 @@ public function getSubheading(): string | Htmlable | null
8891

8992
return new HtmlString(Blade::render($string->toString()));
9093
}
94+
95+
public function getFormFields()
96+
{
97+
return $this->resolveFormFields();
98+
}
9199
}

0 commit comments

Comments
 (0)