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

+3 -1
View File
@@ -28,7 +28,9 @@ public function evaluate(array $form, array $values): array
}
foreach ((array) $form['steps'] as $step) {
$stepVisible = ! $this->any($byTarget['step:'.$step['key']] ?? [], 'skip', $context);
// Ein Bereich lässt sich wie eine Gruppe anzeigen oder ausblenden; „überspringen“ bleibt für ältere Vorlagen gültig.
$stepRules = $byTarget['step:'.$step['key']] ?? [];
$stepVisible = ! $this->any($stepRules, 'skip', $context) && $this->visible($stepRules, $context);
$state['steps'][$step['key']] = $stepVisible;
foreach ($step['items'] as $item) {
+62
View File
@@ -0,0 +1,62 @@
<?php
namespace App\Domain\Communication;
/**
* Der Anfragegrund, mit dem das Widget „Anfrage“ ein veröffentlichtes Formular lädt (ADR-61): ein vorgewähltes Anliegen,
* optional ein Unteranliegen, und die Formularführung. Das ist eine Darstellungs- und Vorauswahlentscheidung, keine
* Berechtigung: Alles, was ein Anfragegrund wählen kann, bietet das veröffentlichte Formular ohnehin an. Aus dem Grund
* entsteht dieselbe Konfiguration wie bei einem Anfrage-Einstieg, damit Auslieferung, Auswertung und Annahme nur eine
* Auslegung haben (FormFactory::effective).
*/
final class FormReason
{
/**
* Bereinigt die Angaben aus der Adresse oder der Anfrage des Browsers: nur bekannte Schlüssel, nur gültige Kennungen.
*
* @param array<string, mixed> $input
* @return array{anliegen: ?string, unteranliegen: ?string, modus: ?string}
*/
public static function clean(array $input): array
{
$key = fn (mixed $value): ?string => Keys::valid($value) ? $value : null;
$mode = $input['modus'] ?? null;
return [
'anliegen' => $key($input['anliegen'] ?? null),
'unteranliegen' => $key($input['unteranliegen'] ?? null),
'modus' => $mode === 'wizard' || $mode === 'compact' ? $mode : null,
];
}
/**
* Die Konfiguration, die FormFactory::effective erwartet. Ein Anliegen, das die Fassung nicht kennt, schränkt
* nichts ein (das Formular fragt dann wie gewohnt).
*
* @param array<string, mixed> $definition aufgelöste Fassung
* @param array<string, mixed> $reason
* @return array<string, mixed>
*/
public static function config(array $definition, array $reason): array
{
$config = ['mode' => ($reason['modus'] ?? null) === 'wizard' ? 'wizard' : 'compact', 'open' => 'inline'];
$issue = $reason['anliegen'] ?? null;
foreach ((array) ($definition['issues'] ?? []) as $top) {
if ($top['key'] !== $issue) {
continue;
}
$config['allowed_issues'] = [$issue];
$config['defaults'] = ['anliegen' => $issue];
$sub = $reason['unteranliegen'] ?? null;
if ($sub !== null && in_array($sub, array_column((array) $top['children'], 'key'), true)) {
$config['allowed_subissues'] = [$sub];
$config['defaults']['unteranliegen'] = $sub;
}
}
return $config;
}
}
+8 -3
View File
@@ -16,9 +16,14 @@
*/
final class FormToken
{
public static function issue(int $entryId, int $versionId): string
/**
* @param string $kind 'entry' (Anfrage-Einstieg) oder 'form' (veröffentlichte Vorlage, vom Widget „Anfrage“ gewählt);
* $entryId ist dann die Kennung des Einstiegs beziehungsweise der Vorlage
*/
public static function issue(int $entryId, int $versionId, string $kind = 'entry'): string
{
return Crypt::encryptString(json_encode([
'k' => $kind === 'form' ? 'form' : 'entry',
'e' => $entryId,
'v' => $versionId,
't' => now()->getTimestamp(),
@@ -27,7 +32,7 @@ public static function issue(int $entryId, int $versionId): string
}
/**
* @return array{e: int, v: int, t: int, n: string}|null
* @return array{k: string, e: int, v: int, t: int, n: string}|null
*/
public static function read(mixed $token): ?array
{
@@ -45,6 +50,6 @@ public static function read(mixed $token): ?array
return null;
}
return ['e' => (int) $data['e'], 'v' => (int) $data['v'], 't' => (int) $data['t'], 'n' => $data['n']];
return ['k' => ($data['k'] ?? 'entry') === 'form' ? 'form' : 'entry', 'e' => (int) $data['e'], 'v' => (int) $data['v'], 't' => (int) $data['t'], 'n' => $data['n']];
}
}
+14
View File
@@ -44,6 +44,20 @@ public function issueTitle(): string
return trim(implode(' › ', array_filter([$this->issue_label, $this->subissue_label])));
}
/**
* Woher die Anfrage kam: der Anfrage-Einstieg (älterer Weg) oder das Formular, das das Widget „Anfrage“ eingebunden hat.
*/
public function channelTitle(): string
{
if ($this->entry !== null) {
return $this->entry->name;
}
$template = $this->templateVersion?->template;
return $template !== null ? 'Formular „'.$template->name.'“' : 'Formular gelöscht';
}
public function contactTitle(): string
{
return $this->contact_name ?: ($this->contact_email ?: 'Unbekannt');
+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,
@@ -295,7 +295,7 @@ private function rules(array $rules, array $fields, array $tree, bool $hasIssue,
}
$kindOk = match ($effect) {
'show', 'hide' => in_array($targetKind, ['group', 'field'], true),
'show', 'hide' => in_array($targetKind, ['step', 'group', 'field'], true),
'require', 'preset' => $targetKind === 'field',
'skip' => $targetKind === 'step',
default => false,