CI Feature / test (push) Successful in 4m17s
Der Editor zeigt Bereiche mit Feldern und Teilbereichen; Felder werden direkt im Bereich angelegt oder aus dem Katalog übernommen und landen im selben Katalog wie bisher. Bedingungen stehen am Feld, Teilbereich oder Bereich und werden zu denselben Regeln wie die Regelliste; alles andere bleibt unter „Weitere Regeln“. Navigation: Anfragen, Formulare & Befragungen, Einstellungen. Anliegen, Feldkatalog, Feldgruppen und Einstiege bleiben erreichbar (Einstellungen). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
87 lines
3.8 KiB
PHP
87 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Communication\Groups;
|
|
|
|
use App\Domain\Communication\InquiryField;
|
|
use App\Domain\Communication\InquiryFieldGroup;
|
|
use App\Filament\Resources\Communication\CommunicationResource;
|
|
use App\Filament\Resources\Communication\Groups\Pages\EditInquiryFieldGroup;
|
|
use App\Filament\Resources\Communication\Groups\Pages\ListInquiryFieldGroups;
|
|
use Filament\Forms\Components\Placeholder;
|
|
use Filament\Forms\Components\Repeater;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
|
|
/**
|
|
* Feldgruppen: fachliche Zusammenstellung von Feldern in fester Reihenfolge, die mehrere Anfragevorlagen verwenden.
|
|
*/
|
|
class InquiryFieldGroupResource extends CommunicationResource
|
|
{
|
|
protected static ?string $model = InquiryFieldGroup::class;
|
|
|
|
protected static ?string $navigationLabel = 'Feldgruppen';
|
|
|
|
protected static ?string $modelLabel = 'Feldgruppe';
|
|
|
|
protected static ?string $pluralModelLabel = 'Feldgruppen';
|
|
|
|
protected static ?string $recordTitleAttribute = 'name';
|
|
|
|
protected static ?string $slug = 'kommunikation/feldgruppen';
|
|
|
|
protected static ?int $navigationSort = 4;
|
|
|
|
/** Technischer Baustein des Formular-Editors: erreichbar über „Einstellungen“, nicht in der Hauptnavigation (ADR-61). */
|
|
public static function shouldRegisterNavigation(): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
TextInput::make('name')->label('Fachliche Bezeichnung')->required()->maxLength(120)
|
|
->helperText('Nur für die Verwaltung, zum Beispiel „Kindergruppe“.'),
|
|
TextInput::make('label')->label('Überschrift im Formular (optional)')->maxLength(200)
|
|
->helperText('Leer: die fachliche Bezeichnung.'),
|
|
Textarea::make('description')->label('Erläuterung im Formular (optional)')->rows(2)->maxLength(600),
|
|
Repeater::make('items')
|
|
->label('Felder der Gruppe')
|
|
->schema([
|
|
Select::make('field')->label('Feld')->required()->searchable()->distinct()
|
|
->options(fn (): array => InquiryField::query()->offered()->orderBy('name')->get()->mapWithKeys(
|
|
fn (InquiryField $field): array => [$field->key => $field->name.' ('.$field->type->label().')']
|
|
)->all()),
|
|
Toggle::make('required')->label('Pflichtfeld')->default(false)
|
|
->helperText('Eine Vorlage kann ein Feld zusätzlich unter einer Bedingung zur Pflicht machen.'),
|
|
])
|
|
->minItems(1)
|
|
->reorderableWithButtons()
|
|
->addActionLabel('Feld hinzufügen')
|
|
->itemLabel(fn (array $state): ?string => InquiryField::query()->where('key', $state['field'] ?? '')->value('name'))
|
|
->helperText('Die Reihenfolge hier ist die Reihenfolge im Formular.'),
|
|
Placeholder::make('key_info')->label('Interne Kennung')->content(fn (?InquiryFieldGroup $record): string => (string) $record?->key)
|
|
->visible(fn (?InquiryFieldGroup $record): bool => $record !== null),
|
|
Toggle::make('active')->label('Zur Verwendung anbieten'),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table->columns([TextColumn::make('name')->label('Bezeichnung')]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListInquiryFieldGroups::route('/'),
|
|
'edit' => EditInquiryFieldGroup::route('/{record}'),
|
|
];
|
|
}
|
|
}
|