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,147 @@
<?php
namespace App\Filament\Resources\Communication\Entries\Pages;
use App\Domain\Communication\FormTexts;
use App\Domain\Communication\InquiryEntry;
use App\Domain\Communication\Publisher;
use App\Filament\Resources\Communication\Entries\InquiryEntryResource;
use App\Filament\Support\ArchivesCommunicationRecords;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Validation\ValidationException;
class EditInquiryEntry extends EditRecord
{
use ArchivesCommunicationRecords;
protected static string $resource = InquiryEntryResource::class;
protected ?bool $hasUnsavedDataChangesAlert = true;
public function getSubheading(): string|Htmlable|null
{
/** @var InquiryEntry $entry */
$entry = $this->getRecord();
if ($entry->archived_at !== null) {
return 'Archiviert.';
}
if ($entry->published_at === null) {
return 'Entwurf. Im CMS lässt sich dieser Einstieg erst nach „Veröffentlichen“ auswählen.';
}
if (! $entry->isLive()) {
return 'Veröffentlicht, wird aber nicht ausgeliefert: Die Anfragevorlage hat keine gültige Fassung.';
}
return 'Veröffentlicht seit '.$entry->published_at->format('d.m.Y').'.'.($entry->hasUnpublishedChanges() ? ' Der Entwurf enthält Änderungen, die noch nicht veröffentlicht sind.' : '');
}
protected function getHeaderActions(): array
{
return [
Action::make('preview')
->label('Vorschau')
->icon('heroicon-o-eye')
->color('gray')
->tooltip('Zeigt den zuletzt gespeicherten Entwurf des Einstiegs mit der gültigen Fassung der Vorlage. Es wird nichts gesendet.')
->url(fn (): string => route('communication.preview.entry', $this->getRecord()))
->openUrlInNewTab(),
Action::make('publish')
->label('Veröffentlichen')
->color('primary')
->visible(fn (): bool => $this->getRecord()->archived_at === null)
->requiresConfirmation()
->modalHeading('Anfrage-Einstieg veröffentlichen')
->modalDescription('Speichert den Entwurf und macht ihn wirksam. Alle Seiten, die diesen Einstieg einbinden, zeigen danach den neuen Stand.')
->action(function (): void {
$this->save(shouldRedirect: false, shouldSendSavedNotification: false);
try {
app(Publisher::class)->publishEntry($this->getRecord());
} catch (ValidationException $e) {
Notification::make()->title('Der Einstieg lässt sich nicht veröffentlichen')->body(implode("\n", array_map(fn (string $line): string => '• '.$line, (array) ($e->errors()['config'] ?? []))))->danger()->persistent()->send();
return;
}
Notification::make()->title('Der Einstieg ist veröffentlicht.')->success()->send();
$this->redirect(InquiryEntryResource::getUrl('edit', ['record' => $this->getRecord()]));
}),
Action::make('withdraw')
->label('Zurückziehen')
->color('gray')
->visible(fn (): bool => $this->getRecord()->published_at !== null)
->requiresConfirmation()
->modalDescription('Der Einstieg wird nicht mehr ausgeliefert; Seiten, die ihn einbinden, zeigen kein Formular. Die Konfiguration bleibt als Entwurf erhalten.')
->action(function (): void {
app(Publisher::class)->withdrawEntry($this->getRecord());
Notification::make()->title('Der Einstieg ist zurückgezogen.')->success()->send();
$this->redirect(InquiryEntryResource::getUrl('edit', ['record' => $this->getRecord()]));
}),
...$this->archiveActions(),
];
}
protected function archiveNote(): string
{
return 'Der Einstieg wird archiviert und nicht mehr ausgeliefert. Eingegangene Anfragen bleiben unverändert.';
}
protected function archiveAttributes(): array
{
return ['archived_at' => now(), 'published_config' => null, 'published_at' => null];
}
protected function indexUrl(): string
{
return InquiryEntryResource::getUrl('index');
}
protected function mutateFormDataBeforeFill(array $data): array
{
$config = array_merge(InquiryEntry::emptyConfig(), (array) ($data['config'] ?? []));
$preselect = [];
foreach ((array) ($config['defaults'] ?? []) as $field => $value) {
$preselect[] = ['field' => $field, 'value' => $value];
}
$config['preselect'] = $preselect;
$data['config'] = $config;
return $data;
}
protected function mutateFormDataBeforeSave(array $data): array
{
$config = (array) ($data['config'] ?? []);
$defaults = [];
foreach (array_values((array) ($config['preselect'] ?? [])) as $row) {
if (is_array($row) && filled($row['field'] ?? null) && filled($row['value'] ?? null)) {
$defaults[(string) $row['field']] = (string) $row['value'];
}
}
$data['config'] = [
'mode' => ($config['mode'] ?? 'compact') === 'wizard' ? 'wizard' : 'compact',
'open' => ($config['open'] ?? 'inline') === 'button' ? 'button' : 'inline',
'allowed_issues' => array_values(array_filter((array) ($config['allowed_issues'] ?? []), 'is_string')),
'allowed_subissues' => array_values(array_filter((array) ($config['allowed_subissues'] ?? []), 'is_string')),
'defaults' => $defaults,
'texts' => FormTexts::clean((array) ($config['texts'] ?? [])),
];
return $data;
}
protected function getRedirectUrl(): ?string
{
return null;
}
}