Liefere das Anfrageformular je Anfragegrund aus und gib dem Widget Gründe, Formularführung und Präsentation

Das Widget Anfrage wählt statt eines Anfrage-Einstiegs mehrere Anfragegründe, jeder zeigt auf ein veröffentlichtes Formular
(optional mit vorgewähltem Anliegen). Der Besucher erhält genau das Formular seines Grundes: /anfrage/formular/{vorlage}
mit Grund in der Adresse, dasselbe Token, dieselbe Auswertung und Annahme. Ein Dialog (dialog-Element) und die Grundauswahl
als Karten oder Auswahlfeld kommen aus resources/js/inquiry-widget.js. Seiten mit einem Einstieg bleiben darstellbar.
Bereiche lassen sich wie Gruppen anzeigen oder ausblenden.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-27 22:29:31 +01:00
1 parent f255bf5200
commit fb479c1b01
18 files changed
+1394 -57

No files matched your search

+55 -3
View File
@@ -50,10 +50,62 @@ public function deliver(InquiryEntry $entry, ?int $versionId = null): ?array
* @throws SubmissionException
*/
public function submit(InquiryEntry $entry, array $payload): array
{
return $this->accept('entry', $entry->id, $entry->id, fn (?int $version): ?array => $this->deliver($entry, $version), $payload);
}
/**
* Die Fassung und das wirksame Formular einer veröffentlichten Vorlage für einen Besucher, wie sie das Widget
* „Anfrage“ ausliefert. $reason legt den Anfragegrund fest: ein vorgewähltes Anliegen (und Unteranliegen) und die
* Formularführung. Null, wenn die Vorlage nicht veröffentlicht oder archiviert ist.
*
* @param array{anliegen?: ?string, unteranliegen?: ?string, modus?: ?string} $reason
* @return array{form: array<string, mixed>, version: InquiryTemplateVersion}|null
*/
public function deliverForm(InquiryTemplate $template, array $reason = [], ?int $versionId = null): ?array
{
$template->loadMissing('publishedVersion');
if ($template->archived_at !== null || $template->publishedVersion === null) {
return null;
}
$version = $template->publishedVersion;
if ($versionId !== null && $versionId !== $version->id) {
$version = InquiryTemplateVersion::query()->where('template_id', $template->id)->find($versionId) ?? $version;
}
return ['form' => $this->factory->effective($version->definition, FormReason::config($version->definition, $reason)), 'version' => $version];
}
/**
* Nimmt eine Anfrage für eine veröffentlichte Vorlage an (Widget „Anfrage“). Die Verarbeitung ist dieselbe wie über
* einen Einstieg; die Anfrage trägt dann keine Einstiegskennung, sondern verweist über ihre Fassung auf die Vorlage.
*
* @param array{anliegen?: ?string, unteranliegen?: ?string, modus?: ?string} $reason
* @param array<string, mixed> $payload
* @return array{reference: string, created: bool}
*
* @throws SubmissionException
*/
public function submitForm(InquiryTemplate $template, array $reason, array $payload): array
{
return $this->accept('form', $template->id, null, fn (?int $version): ?array => $this->deliverForm($template, $reason, $version), $payload);
}
/**
* @param callable(?int): (array{form: array<string, mixed>, version: InquiryTemplateVersion}|null) $deliver
* @param array<string, mixed> $payload
* @return array{reference: string, created: bool}
*
* @throws SubmissionException
*/
private function accept(string $kind, int $targetId, ?int $entryId, callable $deliver, array $payload): array
{
$token = FormToken::read($payload['token'] ?? null);
if ($token === null || $token['e'] !== $entry->id) {
if ($token === null || $token['k'] !== $kind || $token['e'] !== $targetId) {
throw new SubmissionException('Das Formular ist abgelaufen. Bitte laden Sie die Seite neu; Ihre Eingaben bleiben dabei nicht erhalten.', [], 419);
}
@@ -69,7 +121,7 @@ public function submit(InquiryEntry $entry, array $payload): array
return ['reference' => $existing->reference, 'created' => false];
}
$delivered = $this->deliver($entry, $token['v']);
$delivered = $deliver($token['v']);
if ($delivered === null) {
throw new SubmissionException('Dieses Anfrageformular ist zurzeit nicht verfügbar.', [], 410);
@@ -101,7 +153,7 @@ public function submit(InquiryEntry $entry, array $payload): array
try {
$inquiry = DB::transaction(fn (): Inquiry => Inquiry::query()->create([
'reference' => $this->reference(),
'entry_id' => $entry->id,
'entry_id' => $entryId,
'template_version_id' => $delivered['version']->id,
'submission_token' => hash('sha256', $token['n']),
'issue_key' => $result['issue']['key'] ?? null,