*/ private static function customFields(): array { return app(ProfileFields::class)->all()->map(function (ProfileField $field) { $name = 'custom_fields.'.$field->key; $hint = $field->visibility === 'restricted' ? 'Nur für die Person und die Personalverwaltung sichtbar.' : null; $component = match ($field->type) { 'textarea' => Textarea::make($name)->rows(3)->maxLength(5000)->columnSpanFull(), 'date' => DatePicker::make($name)->native(false)->displayFormat('d.m.Y'), 'email' => TextInput::make($name)->email()->maxLength(255), 'url' => TextInput::make($name)->url()->maxLength(500), 'phone' => TextInput::make($name)->tel()->telRegex(self::PHONE_REGEX)->maxLength(50), default => TextInput::make($name)->maxLength(255), }; return $component->label($field->label)->helperText($hint); })->values()->all(); } public static function configure(Schema $schema): Schema { return $schema ->columns(3) ->components([ Section::make('Person') ->columnSpan(2) ->columns(2) ->schema([ TextInput::make('first_name')->label('Vorname')->required()->maxLength(100), TextInput::make('last_name')->label('Nachname')->required()->maxLength(100), TextInput::make('email') ->label('E-Mail-Adresse') ->email() ->required() ->maxLength(255) ->unique(ignoreRecord: true) ->columnSpanFull(), TextInput::make('job_title')->label('Funktion')->maxLength(150), TextInput::make('department')->label('Abteilung')->maxLength(150), TextInput::make('location')->label('Standort')->maxLength(150), // Eigene Regel: Filaments Standard lehnt übliche Schreibweisen wie „+49 (0) 30 123“ ab. TextInput::make('phone')->label('Telefon')->tel()->telRegex(self::PHONE_REGEX)->maxLength(50), TextInput::make('mobile')->label('Mobil')->tel()->telRegex(self::PHONE_REGEX)->maxLength(50), Textarea::make('about')->label('Über mich')->rows(3)->maxLength(2000)->columnSpanFull(), ]), Section::make('Konto') ->columnSpan(1) ->schema([ Toggle::make('is_active') ->label('Aktiv') ->helperText('Deaktivierte Konten können sich nicht anmelden und erscheinen nicht im Portal.') ->default(true), Select::make('manual_roles') ->label('Rollen') ->helperText('Rollen sind additiv. Rollen aus Identity-Provider-Gruppen werden automatisch vergeben.') ->multiple() ->preload() ->options(fn () => Role::query()->orderByDesc('is_system')->orderBy('name')->pluck('name', 'id')->all()) ->afterStateHydrated(function (Select $component, ?User $record) { $component->state($record?->roles()->wherePivot('source', 'manual')->pluck('roles.id')->all() ?? []); }) ->rule(function (?User $record) { // Die eigene Administrationsrolle kann man sich nicht selbst entziehen. return function (string $attribute, mixed $value, \Closure $fail) use ($record) { if ($record?->is(auth()->user()) && $record->hasRole(Role::ADMINISTRATION) && ! in_array(Role::administration()->id, array_map('intval', (array) $value), true)) { $fail('Die eigene Rolle „Administration“ kann nicht entfernt werden.'); } }; }) ->saveRelationshipsUsing(fn (User $record, ?array $state) => $record->syncManualRoles(array_map('intval', $state ?? []))) ->dehydrated(false), TextInput::make('password') ->label(fn (string $operation) => $operation === 'create' ? 'Passwort' : 'Neues Passwort') ->helperText(fn (string $operation) => $operation === 'create' ? 'Leer lassen, wenn sich die Person nur über den Identity Provider anmelden soll.' : 'Leer lassen, um das Passwort nicht zu ändern.') ->password() ->revealable() ->rule(Password::default()) ->dehydrated(fn (?string $state) => filled($state)), ]), Section::make('Weitere Angaben') ->columnSpan(2) ->columns(2) ->schema(fn () => self::customFields()) ->visible(fn () => app(ProfileFields::class)->all()->isNotEmpty()), ]); } }