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}'),
];
}
}
@@ -0,0 +1,55 @@
<?php
namespace App\Filament\Resources\Communication\Fields\Pages;
use App\Domain\Communication\FieldType;
use App\Domain\Communication\InquiryField;
use App\Domain\Communication\Keys;
use App\Filament\Resources\Communication\Fields\InquiryFieldResource;
use App\Filament\Support\ArchivesCommunicationRecords;
use Filament\Resources\Pages\EditRecord;
class EditInquiryField extends EditRecord
{
use ArchivesCommunicationRecords;
protected static string $resource = InquiryFieldResource::class;
protected function getHeaderActions(): array
{
return $this->archiveActions();
}
protected function archiveNote(): string
{
return 'Das Feld kann in keiner neuen Fassung einer Vorlage mehr verwendet werden. Veröffentlichte Fassungen und eingegangene Anfragen bleiben unverändert.';
}
protected function indexUrl(): string
{
return InquiryFieldResource::getUrl('index');
}
protected function mutateFormDataBeforeSave(array $data): array
{
/** @var InquiryField $record */
$record = $this->getRecord();
$type = $record->type;
$data['options'] = $type->hasOptions() ? Keys::withKeys((array) ($data['options'] ?? [])) : null;
$settings = array_filter((array) ($data['settings'] ?? []), fn (mixed $value): bool => $value !== null && $value !== '');
$data['settings'] = match ($type) {
FieldType::Text, FieldType::Textarea => array_intersect_key($settings, ['max_length' => true]),
FieldType::Number => array_intersect_key($settings, ['min' => true, 'max' => true]),
default => [],
};
return $data;
}
protected function getRedirectUrl(): ?string
{
return InquiryFieldResource::getUrl('index');
}
}
@@ -0,0 +1,117 @@
<?php
namespace App\Filament\Resources\Communication\Fields\Pages;
use App\Domain\Communication\FieldType;
use App\Domain\Communication\InquiryField;
use App\Domain\Communication\InquiryFieldGroup;
use App\Domain\Communication\Keys;
use App\Filament\Resources\Communication\Fields\InquiryFieldResource;
use App\Filament\Support\ListsCatalog;
use Filament\Actions\Action;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\Support\Htmlable;
class ListInquiryFields extends ListRecords
{
use ListsCatalog;
protected static string $resource = InquiryFieldResource::class;
public function getSubheading(): string|Htmlable|null
{
return 'Der Feldkatalog enthält alle Eingabefelder, die Anfragevorlagen verwenden können. Ein Feld wie „Postleitzahl“ oder „Telefonnummer“ wird einmal angelegt und überall wiederverwendet. Felder werden nie gelöscht, nur deaktiviert oder archiviert.';
}
protected function getHeaderActions(): array
{
return [
Action::make('create')
->label('Feld anlegen')
->modalHeading('Neues Feld')
->modalDescription('Weitere Angaben wie Hilfetext, Grenzen oder die Verwendung in der Anfrageübersicht legst du danach fest.')
->modalSubmitActionLabel('Feld anlegen')
->schema([
TextInput::make('name')->label('Fachliche Bezeichnung')->required()->maxLength(120),
TextInput::make('label')->label('Öffentliche Beschriftung')->required()->maxLength(200),
Select::make('type')->label('Feldtyp')->options(FieldType::options())->required()->live(),
...InquiryFieldResource::optionsFields(),
])
->action(function (array $data): void {
$field = InquiryField::query()->create([
'key' => Keys::from($data['name'], InquiryField::query()->pluck('key')->all()),
'name' => $data['name'],
'label' => $data['label'],
'type' => $data['type'],
'options' => FieldType::from($data['type'])->hasOptions() ? Keys::withKeys((array) ($data['options'] ?? [])) : null,
]);
Notification::make()->title('Das Feld ist angelegt.')->success()->send();
$this->redirect(InquiryFieldResource::getUrl('edit', ['record' => $field]));
}),
];
}
protected function catalogRows(): array
{
$usage = [];
foreach (InquiryFieldGroup::query()->get() as $group) {
foreach ($group->itemList() as $item) {
$usage[$item['field']] = ($usage[$item['field']] ?? 0) + 1;
}
}
$rows = [];
foreach (InquiryField::query()->orderBy('name')->get() as $field) {
$url = InquiryFieldResource::getUrl('edit', ['record' => $field]);
$state = $field->archived_at !== null ? 'archiviert' : ($field->active ? 'aktiv' : 'inaktiv');
$used = $usage[$field->key] ?? 0;
$rows[] = [
'schluessel' => 'f'.$field->id,
'titel' => $field->name,
'meta' => $field->type->label().' · '.$field->key,
'text' => $field->label,
'suchtext' => $field->key.' '.$field->label,
'symbol' => 'modul',
'url' => $url,
'chips' => array_values(array_filter([
match ($state) {
'aktiv' => ['label' => 'Wird angeboten', 'ton' => 'gut'],
'inaktiv' => ['label' => 'Deaktiviert', 'ton' => 'leise'],
default => ['label' => 'Archiviert', 'ton' => 'leise'],
},
['label' => $used === 0 ? 'In keiner Feldgruppe' : ($used === 1 ? 'In 1 Feldgruppe' : "In $used Feldgruppen"), 'ton' => 'neutral'],
$field->purpose !== null ? ['label' => $field->purpose->label(), 'ton' => 'neutral'] : null,
])),
'zustand' => [$state, 'typ_'.$field->type->value],
'aktionen' => [['label' => 'Bearbeiten', 'href' => $url, 'icon' => 'stift']],
];
}
return $rows;
}
protected function zustandOptionen(): array
{
return ['alle' => 'Jeder Zustand', 'aktiv' => 'Wird angeboten', 'inaktiv' => 'Deaktiviert', 'archiviert' => 'Archiviert'];
}
protected function suchPlatzhalter(): string
{
return 'Bezeichnung, Beschriftung oder Kennung';
}
protected function einheit(): array
{
return ['Feld', 'Felder'];
}
protected function leer(): array
{
return ['titel' => 'Noch keine Felder', 'text' => 'Mit „Feld anlegen“ oben entsteht das erste Feld, zum Beispiel „E-Mail-Adresse“.'];
}
}