Baue die Verwaltung Kommunikation, die öffentliche Anfrageschnittstelle und das CMS-Widget Anfrage

Anliegen, Feldkatalog, Feldgruppen, Anfragevorlagen mit Fassungen, Anfrage-Einstiege, Posteingang mit
Status und Notizen, Einstellungen mit Empfängern. Das Widget speichert nur die Kennung eines veröffentlichten
Einstiegs; Formular, Bedingungen und Annahme kommen zur Laufzeit vom Server (Kompaktformular und
mehrstufiger Dialog aus derselben Beschreibung).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-27 17:41:55 +01:00
1 parent 2ee1fc9866
commit c6a8167601
45 files changed
+5415

No files matched your search

@@ -0,0 +1,120 @@
<?php
namespace App\Filament\Resources\Communication\Fields;
use App\Domain\Communication\FieldPurpose;
use App\Domain\Communication\FieldType;
use App\Domain\Communication\InquiryField;
use App\Filament\Resources\Communication\CommunicationResource;
use App\Filament\Resources\Communication\Fields\Pages\EditInquiryField;
use App\Filament\Resources\Communication\Fields\Pages\ListInquiryFields;
use Closure;
use Filament\Forms\Components\Hidden;
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\Components\Component;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
/**
* Feldkatalog: wiederverwendbare Eingabefelder. Ein Feld wird einmal definiert und in beliebig vielen Feldgruppen und
* Anfragevorlagen verwendet.
*/
class InquiryFieldResource extends CommunicationResource
{
protected static ?string $model = InquiryField::class;
protected static ?string $navigationLabel = 'Feldkatalog';
protected static ?string $modelLabel = 'Feld';
protected static ?string $pluralModelLabel = 'Felder';
protected static ?string $recordTitleAttribute = 'name';
protected static ?string $slug = 'kommunikation/felder';
protected static ?int $navigationSort = 3;
/**
* @return list<Component>
*/
public static function optionsFields(): array
{
return [
Repeater::make('options')
->label('Auswahlwerte')
->schema([
Hidden::make('key'),
TextInput::make('label')->label('Bezeichnung')->required()->maxLength(120),
])
->minItems(1)
->reorderableWithButtons()
->addActionLabel('Auswahlwert hinzufügen')
->itemLabel(fn (array $state): ?string => $state['label'] ?? null)
->helperText('Reihenfolge wie hier. Jeder Wert erhält eine feste interne Kennung; eine Umbenennung ändert sie nicht und beschädigt keine Anfragen.')
->visible(fn (Get $get): bool => FieldType::tryFrom((string) $get('type'))?->hasOptions() ?? false)
->required(fn (Get $get): bool => FieldType::tryFrom((string) $get('type'))?->hasOptions() ?? false),
];
}
public static function form(Schema $schema): Schema
{
return $schema->components([
Section::make('Feld')->schema([
TextInput::make('name')->label('Fachliche Bezeichnung')->required()->maxLength(120)
->helperText('Nur für die Verwaltung, zum Beispiel „Postleitzahl (Einrichtung)“.'),
TextInput::make('label')->label('Öffentliche Beschriftung')->required()->maxLength(200)
->helperText('So heißt das Feld im Formular.'),
Textarea::make('help')->label('Hilfetext (optional)')->rows(2)->maxLength(600)
->helperText('Steht unter der Beschriftung.'),
Select::make('type')->label('Feldtyp')->options(FieldType::options())->required()->live()
->disabled(fn (?InquiryField $record): bool => $record !== null)
->dehydrated(fn (?InquiryField $record): bool => $record === null)
->helperText('Nach dem Anlegen nicht mehr änderbar, weil Bedingungen und Gruppen darauf aufbauen.'),
...self::optionsFields(),
TextInput::make('settings.max_length')->label('Höchste Textlänge')->numeric()->minValue(1)->maxValue(8000)
->visible(fn (Get $get): bool => in_array($get('type'), ['text', 'textarea'], true))
->helperText('Leer: Vorgabe (200 Zeichen einzeilig, 4000 mehrzeilig).'),
TextInput::make('settings.min')->label('Kleinster Wert')->numeric()
->visible(fn (Get $get): bool => $get('type') === 'number'),
TextInput::make('settings.max')->label('Größter Wert')->numeric()
->visible(fn (Get $get): bool => $get('type') === 'number'),
Select::make('purpose')->label('Verwendung in der Anfrageübersicht')->options(FieldPurpose::options())->placeholder('Keine besondere Verwendung')
->helperText('Welche Angabe der Posteingang als Name, E-Mail-Adresse oder Nachricht der Anfrage zeigt. Jede Vorlage braucht ein Feld „E-Mail-Adresse für Rückfragen“.')
->rule(fn (Get $get): Closure => function (string $attribute, mixed $value, Closure $fail) use ($get): void {
$type = FieldType::tryFrom((string) $get('type'));
if ($value !== null && $type !== null && ! in_array($type, FieldPurpose::from($value)->types(), true)) {
$fail('Diese Verwendung passt nicht zum Feldtyp „'.$type->label().'“.');
}
}),
Placeholder::make('key_info')->label('Interne Kennung')->content(fn (?InquiryField $record): string => (string) $record?->key)
->visible(fn (?InquiryField $record): bool => $record !== null)
->helperText('Ändert sich nie.'),
Toggle::make('active')->label('Zur Verwendung anbieten')
->helperText('Ausgeschaltet kann das Feld in keiner neuen Fassung einer Vorlage verwendet werden; bestehende Fassungen und Anfragen bleiben unverändert.'),
]),
]);
}
public static function table(Table $table): Table
{
return $table->columns([TextColumn::make('name')->label('Bezeichnung')]);
}
public static function getPages(): array
{
return [
'index' => ListInquiryFields::route('/'),
'edit' => EditInquiryField::route('/{record}'),
];
}
}