CI Feature / test (push) Successful in 5m32s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
479 lines
24 KiB
PHP
479 lines
24 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Support;
|
||
|
||
use App\Domain\Communication\FieldPurpose;
|
||
use App\Domain\Communication\FieldType;
|
||
use App\Domain\Communication\FormEditor;
|
||
use App\Domain\Communication\FormTexts;
|
||
use App\Domain\Communication\InquiryField;
|
||
use App\Domain\Communication\InquiryIssue;
|
||
use App\Domain\Communication\TemplateCompiler;
|
||
use Filament\Forms\Components\Builder;
|
||
use Filament\Forms\Components\Builder\Block;
|
||
use Filament\Forms\Components\Hidden;
|
||
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\Tabs;
|
||
use Filament\Schemas\Components\Tabs\Tab;
|
||
use Filament\Schemas\Components\Text;
|
||
use Filament\Schemas\Components\Utilities\Get;
|
||
use Filament\Schemas\Components\Utilities\Set;
|
||
use Illuminate\Support\Str;
|
||
|
||
/**
|
||
* Formular-Editor (ADR-61): ein Formular wird an einer Stelle bearbeitet. Es besteht aus Bereichen (im mehrstufigen Dialog
|
||
* je ein Schritt), darin Felder und Teilbereiche, Bedingungen direkt am Element. Felder werden hier angelegt und
|
||
* geändert; sie landen im selben Katalog wie bisher (FormEditor). Die Regelliste bleibt für alles, was sich nicht an ein
|
||
* Element heften lässt. Alles sind Auswahlfelder und Listen; es gibt keine freie Eingabe von Ausdrücken oder JSON.
|
||
*/
|
||
final class TemplateEditor
|
||
{
|
||
private const EFFECT_LABELS = [
|
||
'step' => ['show' => 'Bereich nur anzeigen, wenn …', 'hide' => 'Bereich ausblenden, wenn …', 'skip' => 'Bereich überspringen, wenn …'],
|
||
'group' => ['show' => 'Teilbereich nur anzeigen, wenn …', 'hide' => 'Teilbereich ausblenden, wenn …'],
|
||
'field' => ['show' => 'Feld nur anzeigen, wenn …', 'hide' => 'Feld ausblenden, wenn …', 'require' => 'Pflichtfeld, wenn …'],
|
||
];
|
||
|
||
/**
|
||
* @return list<Component>
|
||
*/
|
||
public static function schema(): array
|
||
{
|
||
return [
|
||
TextInput::make('name')->label('Name des Formulars')->required()->maxLength(120)
|
||
->helperText('So heißt das Formular in der Verwaltung und in der Auswahl des Widgets „Anfrage“.'),
|
||
Textarea::make('description')->label('Beschreibung (nur Verwaltung)')->rows(2)->maxLength(400),
|
||
Tabs::make('vorlage')->persistTabInQueryString('bereich')->tabs([
|
||
Tab::make('Aufbau')->icon('heroicon-o-queue-list')->schema(self::structure()),
|
||
Tab::make('Texte')->icon('heroicon-o-chat-bubble-bottom-center-text')->schema(self::texts()),
|
||
Tab::make('Weitere Regeln')->icon('heroicon-o-adjustments-horizontal')->schema(self::rules()),
|
||
]),
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @return list<Component>
|
||
*/
|
||
private static function structure(): array
|
||
{
|
||
return [
|
||
Text::make('Ein Formular besteht aus Bereichen. Im mehrstufigen Dialog ist jeder Bereich ein Schritt, im langen Formular stehen alle Bereiche untereinander. In einem Bereich legst du Felder an; ein Teilbereich fasst Felder unter einer Überschrift zusammen. Bedingungen stehen direkt am Feld oder Bereich. Neue Felder und Auswahlwerte stehen in Bedingungen zur Verfügung, sobald das Formular einmal gespeichert ist.'),
|
||
Repeater::make('editor.areas')
|
||
->label('Bereiche')
|
||
->schema([
|
||
Hidden::make('key')->default(fn (): string => 's'.Str::lower(Str::random(6))),
|
||
TextInput::make('title')->label('Titel des Bereichs')->required()->maxLength(120)->live(onBlur: true)
|
||
->helperText('Im mehrstufigen Dialog die Überschrift des Schritts.'),
|
||
Textarea::make('intro')->label('Einleitung (optional)')->rows(2)->maxLength(600),
|
||
self::condition('step'),
|
||
Builder::make('items')
|
||
->label('Inhalt des Bereichs')
|
||
->blocks(self::blocks())
|
||
->addActionLabel('Feld oder Teilbereich hinzufügen')
|
||
->blockPickerColumns(2)
|
||
->blockNumbers(false)
|
||
->reorderableWithButtons()
|
||
->collapsible()
|
||
->live(),
|
||
])
|
||
->reorderableWithButtons()
|
||
->collapsible()
|
||
->addActionLabel('Bereich hinzufügen')
|
||
->live()
|
||
->itemLabel(fn (array $state): string => (($state['title'] ?? '') ?: 'Neuer Bereich').(filled($state['cond']['effect'] ?? null) ? ' · mit Bedingung' : '')),
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @return list<Block>
|
||
*/
|
||
private static function blocks(): array
|
||
{
|
||
return [
|
||
Block::make('field')
|
||
->label(fn (?array $state): string => $state === null ? 'Feld' : 'Feld: '.(($state['label'] ?? '') ?: 'neu').self::fieldBadges($state))
|
||
->icon('heroicon-o-pencil-square')
|
||
->schema([
|
||
Hidden::make('key')->default(fn (): string => FormEditor::temporaryKey()),
|
||
Hidden::make('name'),
|
||
Hidden::make('used_in'),
|
||
Select::make('pick')->label('Vorhandenes Feld verwenden (optional)')->searchable()->live()->dehydrated(false)
|
||
->options(fn ($livewire): array => self::catalogFields((array) ($livewire->data['editor'] ?? [])))
|
||
->placeholder('Neues Feld anlegen')
|
||
->visible(fn (Get $get): bool => str_starts_with((string) $get('key'), 'tmp_'))
|
||
->afterStateUpdated(function ($state, Set $set): void {
|
||
$field = filled($state) ? InquiryField::query()->where('key', $state)->first() : null;
|
||
|
||
if ($field === null) {
|
||
return;
|
||
}
|
||
|
||
$set('key', $field->key);
|
||
$set('name', $field->name);
|
||
$set('label', $field->label);
|
||
$set('help', $field->help);
|
||
$set('type', $field->type->value);
|
||
$set('options', $field->optionList());
|
||
$set('purpose', $field->purpose?->value);
|
||
$set('pick', null);
|
||
})
|
||
->helperText('Felder wie „E-Mail-Adresse“ lassen sich in mehreren Formularen verwenden.'),
|
||
TextInput::make('label')->label('Frage oder Beschriftung im Formular')->required()->maxLength(200)->live(onBlur: true),
|
||
Select::make('type')->label('Art der Antwort')->required()->live()->dehydrated()
|
||
->options(FieldType::options())
|
||
->disabled(fn (Get $get): bool => ! str_starts_with((string) $get('key'), 'tmp_'))
|
||
->helperText('Nach dem Speichern nicht mehr änderbar, weil Bedingungen und bisherige Anfragen darauf aufbauen. Soll sich die Art ändern, lege ein neues Feld an.'),
|
||
Repeater::make('options')->label('Auswahlwerte')
|
||
->schema([Hidden::make('key'), TextInput::make('label')->label('Bezeichnung')->required()->maxLength(120)])
|
||
->reorderableWithButtons()
|
||
->addActionLabel('Auswahlwert hinzufügen')
|
||
->minItems(1)
|
||
->itemLabel(fn (array $state): ?string => $state['label'] ?? null)
|
||
->visible(fn (Get $get): bool => FieldType::tryFrom((string) $get('type'))?->hasOptions() ?? false)
|
||
->helperText('Jeder Wert behält seine feste interne Kennung; eine Umbenennung beschädigt keine Anfragen.'),
|
||
Textarea::make('help')->label('Hilfetext (optional)')->rows(2)->maxLength(600)->helperText('Steht unter der Frage.'),
|
||
Toggle::make('required')->label('Pflichtfeld'),
|
||
Section::make('Weitere Einstellungen')->compact()->collapsed()->schema([
|
||
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 zeigt. Jedes Formular braucht ein Feld „E-Mail-Adresse für Rückfragen“.'),
|
||
]),
|
||
Text::make(fn (Get $get): string => 'Dieses Feld wird auch in diesen Formularen verwendet: '.$get('used_in').'. Eine Änderung gilt dort mit der nächsten Veröffentlichung.')
|
||
->visible(fn (Get $get): bool => filled($get('used_in'))),
|
||
self::condition('field'),
|
||
]),
|
||
Block::make('section')
|
||
->label(fn (?array $state): string => $state === null ? 'Teilbereich' : 'Teilbereich: '.(($state['label'] ?? '') ?: 'neu').(filled($state['cond']['effect'] ?? null) ? ' (Bedingung)' : ''))
|
||
->icon('heroicon-o-rectangle-group')
|
||
->schema([
|
||
Hidden::make('key')->default(fn (): string => FormEditor::temporaryKey()),
|
||
Hidden::make('missing')->default(false),
|
||
Hidden::make('used_in'),
|
||
TextInput::make('label')->label('Überschrift des Teilbereichs')->required()->maxLength(200)->live(onBlur: true)
|
||
->helperText('Die Felder darunter stehen im Formular unter dieser Überschrift, bis ein weiterer Teilbereich oder „Ende des Teilbereichs“ folgt.'),
|
||
Textarea::make('description')->label('Erläuterung (optional)')->rows(2)->maxLength(600),
|
||
Text::make(fn (Get $get): string => 'Dieser Teilbereich wird auch in diesen Formularen verwendet: '.$get('used_in').'. Änderungen an seinen Feldern gelten dort mit der nächsten Veröffentlichung.')
|
||
->visible(fn (Get $get): bool => filled($get('used_in'))),
|
||
self::condition('group'),
|
||
]),
|
||
Block::make('end')
|
||
->label('Ende des Teilbereichs')
|
||
->icon('heroicon-o-arrow-uturn-down')
|
||
->schema([Text::make('Die folgenden Felder stehen wieder ohne Teilbereich.')]),
|
||
Block::make('issue')
|
||
->label('Frage nach dem Anliegen')
|
||
->icon('heroicon-o-chat-bubble-left-right')
|
||
->maxItems(1)
|
||
->schema([
|
||
Select::make('issues')->label('Angebotene Anliegen')->multiple()->live()
|
||
->options(fn (): array => InquiryIssue::query()->offered()->whereNull('parent_id')->orderBy('sort_order')->pluck('label', 'key')->all())
|
||
->helperText('Welche Anliegen dieses Formular kennt. Leer: alle angebotenen. Ein Anfragegrund im Widget kann daraus eines vorwählen; die Frage entfällt dann. Anliegen und Unteranliegen pflegst du unter „Einstellungen → Anliegen“.'),
|
||
]),
|
||
];
|
||
}
|
||
|
||
/**
|
||
* Bedingung am Element: Wirkung, Verknüpfung und eine Liste von Vergleichen. Ohne Wirkung gibt es keine Bedingung.
|
||
*/
|
||
private static function condition(string $kind): Section
|
||
{
|
||
return Section::make('Bedingung (optional)')->statePath('cond')->compact()->collapsed()->schema([
|
||
Hidden::make('pos'),
|
||
Select::make('effect')->label('Wirkung')->options(self::EFFECT_LABELS[$kind])->placeholder('Keine Bedingung')->live()
|
||
->helperText($kind === 'step' ? 'Zum Beispiel: Bereich „Angaben zur Schule“ nur anzeigen, wenn das Anliegen „Kursanfrage“ ist.' : null),
|
||
Select::make('match')->label('Es müssen zutreffen')->options(['all' => 'alle Bedingungen', 'any' => 'mindestens eine Bedingung'])->default('all')
|
||
->visible(fn (Get $get): bool => filled($get('effect'))),
|
||
Repeater::make('conditions')
|
||
->label('Bedingungen')
|
||
->schema([
|
||
Select::make('source')->label('Wenn …')->required()->live()->searchable()
|
||
->options(fn (Select $component, $livewire): array => self::sources((array) ($livewire->data['editor'] ?? []), $component->getStatePath())),
|
||
Select::make('op')->label('Vergleich')->required()->options(TemplateCompiler::OPERATORS)->default('eq')->live(),
|
||
Select::make('values')->label('Wert')->required()->multiple()
|
||
->options(fn (Get $get, $livewire): array => self::sourceValues((array) ($livewire->data['editor'] ?? []), (string) $get('source'))),
|
||
])
|
||
->addActionLabel('Bedingung hinzufügen')
|
||
->visible(fn (Get $get): bool => filled($get('effect')))
|
||
->helperText('Zur Auswahl stehen Felder, die im Formular weiter oben stehen.'),
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* @param array<string, mixed>|null $state
|
||
*/
|
||
private static function fieldBadges(?array $state): string
|
||
{
|
||
$parts = [];
|
||
|
||
if (filled($state['type'] ?? null)) {
|
||
$parts[] = FieldType::tryFrom((string) $state['type'])?->label();
|
||
}
|
||
|
||
if ($state['required'] ?? false) {
|
||
$parts[] = 'Pflicht';
|
||
}
|
||
|
||
if (filled($state['cond']['effect'] ?? null)) {
|
||
$parts[] = 'Bedingung';
|
||
}
|
||
|
||
$parts = array_filter($parts);
|
||
|
||
return $parts === [] ? '' : ' ('.implode(', ', $parts).')';
|
||
}
|
||
|
||
/**
|
||
* @return list<Component>
|
||
*/
|
||
private static function rules(): array
|
||
{
|
||
return [
|
||
Section::make()->schema([
|
||
Text::make('Hier stehen Regeln, die sich nicht an ein einzelnes Feld oder einen Bereich heften lassen: weitere Regeln für dasselbe Ziel und Vorbelegungen. Bedingungen für ein Feld oder einen Bereich legst du direkt am Element an. Eine Bedingung darf nur auf Felder verweisen, die im Formular weiter oben stehen.'),
|
||
Repeater::make('editor.rules')
|
||
->label('Weitere Regeln')
|
||
->schema([
|
||
Hidden::make('pos'),
|
||
Select::make('effect')->label('Wirkung')->required()->live()->options(TemplateCompiler::EFFECTS),
|
||
Select::make('target')->label('Ziel')->required()->live()->searchable()
|
||
->options(fn ($livewire, Get $get): array => self::targets((array) ($livewire->data['editor'] ?? []), (string) $get('effect'))),
|
||
Select::make('value')->label('Vorbelegen mit')->live()
|
||
->options(fn (Get $get): array => str_starts_with((string) $get('target'), 'field:') ? self::fieldValues(substr((string) $get('target'), 6)) : [])
|
||
->visible(fn (Get $get): bool => $get('effect') === 'preset')->required(fn (Get $get): bool => $get('effect') === 'preset'),
|
||
Select::make('match')->label('Es müssen zutreffen')->options(['all' => 'alle Bedingungen', 'any' => 'mindestens eine Bedingung'])->default('all')->required(),
|
||
Repeater::make('conditions')
|
||
->label('Bedingungen')
|
||
->schema([
|
||
Select::make('source')->label('Wenn …')->required()->live()->searchable()
|
||
->options(fn ($livewire): array => self::sources((array) ($livewire->data['editor'] ?? []), null)),
|
||
Select::make('op')->label('Vergleich')->required()->options(TemplateCompiler::OPERATORS)->default('eq')->live(),
|
||
Select::make('values')->label('Wert')->required()->multiple()
|
||
->options(fn ($livewire, Get $get): array => self::sourceValues((array) ($livewire->data['editor'] ?? []), (string) $get('source'))),
|
||
])
|
||
->minItems(1)
|
||
->addActionLabel('Bedingung hinzufügen'),
|
||
])
|
||
->collapsible()
|
||
->addActionLabel('Regel hinzufügen')
|
||
->itemLabel(fn (array $state, $livewire): string => (TemplateCompiler::EFFECTS[$state['effect'] ?? ''] ?? 'Neue Regel').(($state['target'] ?? null) ? ' → '.self::targetName((string) $state['target'], (array) ($livewire->data['editor'] ?? [])) : '')),
|
||
]),
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @return list<Component>
|
||
*/
|
||
private static function texts(): array
|
||
{
|
||
$fields = [];
|
||
|
||
foreach (FormTexts::FIELDS as $key => [$label, $default, $help, $multiline]) {
|
||
$field = $multiline
|
||
? Textarea::make("draft.texts.$key")->rows(2)->maxLength(1500)
|
||
: TextInput::make("draft.texts.$key")->maxLength(200);
|
||
|
||
$fields[] = $field->label($label)->placeholder($default !== '' ? $default : 'Kein Text')->helperText($help);
|
||
}
|
||
|
||
return [
|
||
Section::make('Texte des Formulars')
|
||
->description('Alle Texte des Formulars werden hier gepflegt, nie im CMS. Leer lassen: es gilt der grau angezeigte Standardtext.')
|
||
->schema($fields),
|
||
];
|
||
}
|
||
|
||
/**
|
||
* Felder des Katalogs, die im Formular noch nicht vorkommen.
|
||
*
|
||
* @param array<string, mixed> $editor
|
||
* @return array<string, string>
|
||
*/
|
||
private static function catalogFields(array $editor): array
|
||
{
|
||
$used = array_keys(self::inventory($editor)['fields']);
|
||
|
||
return InquiryField::query()->offered()->whereNotIn('key', $used)->orderBy('name')->pluck('name', 'key')->all();
|
||
}
|
||
|
||
/**
|
||
* Inhalt des Formulars in Reihenfolge: Bereiche, Teilbereiche, Felder, und ob die Frage nach dem Anliegen vorkommt.
|
||
*
|
||
* @param array<string, mixed> $editor
|
||
* @return array{steps: array<string, string>, groups: array<string, string>, fields: array<string, string>, hasIssue: bool, issues: list<string>}
|
||
*/
|
||
private static function inventory(array $editor): array
|
||
{
|
||
$steps = [];
|
||
$groups = [];
|
||
$fields = [];
|
||
$hasIssue = false;
|
||
$issues = [];
|
||
|
||
foreach (array_values((array) ($editor['areas'] ?? [])) as $area) {
|
||
$key = (string) ($area['key'] ?? '');
|
||
|
||
if ($key !== '') {
|
||
$steps[$key] = (string) (($area['title'] ?? '') ?: 'Bereich');
|
||
}
|
||
|
||
foreach (array_values((array) ($area['items'] ?? [])) as $block) {
|
||
$data = (array) ($block['data'] ?? []);
|
||
$type = $block['type'] ?? null;
|
||
|
||
if ($type === 'issue') {
|
||
$hasIssue = true;
|
||
$issues = array_values(array_filter((array) ($data['issues'] ?? []), 'is_string'));
|
||
} elseif ($type === 'section' && filled($data['key'] ?? null)) {
|
||
$groups[(string) $data['key']] = (string) (($data['label'] ?? '') ?: 'Teilbereich');
|
||
} elseif ($type === 'field' && filled($data['key'] ?? null)) {
|
||
$fields[(string) $data['key']] = (string) (($data['label'] ?? '') ?: 'Feld');
|
||
}
|
||
}
|
||
}
|
||
|
||
return ['steps' => $steps, 'groups' => $groups, 'fields' => $fields, 'hasIssue' => $hasIssue, 'issues' => $issues];
|
||
}
|
||
|
||
/**
|
||
* @param array<string, mixed> $editor
|
||
* @return array<string, mixed>
|
||
*/
|
||
private static function targets(array $editor, string $effect): array
|
||
{
|
||
$inventory = self::inventory($editor);
|
||
$steps = [];
|
||
foreach ($inventory['steps'] as $key => $title) {
|
||
$steps["step:$key"] = 'Bereich: '.$title;
|
||
}
|
||
$groups = [];
|
||
foreach ($inventory['groups'] as $key => $name) {
|
||
$groups["group:$key"] = 'Teilbereich: '.$name;
|
||
}
|
||
$fields = [];
|
||
foreach ($inventory['fields'] as $key => $name) {
|
||
$fields["field:$key"] = 'Feld: '.$name;
|
||
}
|
||
|
||
return match ($effect) {
|
||
'skip' => $steps,
|
||
'require', 'preset' => $fields,
|
||
default => ['Bereiche' => $steps, 'Teilbereiche' => $groups, 'Felder' => $fields],
|
||
};
|
||
}
|
||
|
||
/**
|
||
* @param array<string, mixed> $editor
|
||
*/
|
||
private static function targetName(string $target, array $editor = []): string
|
||
{
|
||
[$kind, $key] = array_pad(explode(':', $target, 2), 2, '');
|
||
$inventory = self::inventory($editor);
|
||
|
||
return match ($kind) {
|
||
'step' => (string) ($inventory['steps'][$key] ?? $key),
|
||
'field' => (string) ($inventory['fields'][$key] ?? InquiryField::query()->where('key', $key)->value('name') ?? $key),
|
||
'group' => (string) ($inventory['groups'][$key] ?? $key),
|
||
default => $key,
|
||
};
|
||
}
|
||
|
||
/**
|
||
* Felder, auf deren Wert sich eine Bedingung stützen darf: gespeicherte Auswahlfelder und Ja/Nein-Felder. Mit
|
||
* Zustandspfad der Bedingung nur Felder, die im Formular davor stehen (sonst lehnt die Prüfung die Regel ab).
|
||
*
|
||
* @param array<string, mixed> $editor
|
||
* @return array<string, string>
|
||
*/
|
||
private static function sources(array $editor, ?string $path): array
|
||
{
|
||
$areaId = null;
|
||
$blockId = null;
|
||
|
||
if ($path !== null) {
|
||
$segments = explode('.', $path);
|
||
$areaAt = array_search('areas', $segments, true);
|
||
$itemAt = array_search('items', $segments, true);
|
||
$areaId = $areaAt === false ? null : ($segments[$areaAt + 1] ?? null);
|
||
$blockId = $itemAt === false ? null : ($segments[$itemAt + 1] ?? null);
|
||
}
|
||
|
||
$catalog = InquiryField::query()->get()->keyBy('key');
|
||
$sources = [];
|
||
|
||
foreach ((array) ($editor['areas'] ?? []) as $currentArea => $area) {
|
||
if ($areaId !== null && (string) $currentArea === $areaId && $blockId === null) {
|
||
break;
|
||
}
|
||
|
||
foreach ((array) ($area['items'] ?? []) as $currentBlock => $block) {
|
||
if ($areaId !== null && (string) $currentArea === $areaId && (string) $currentBlock === $blockId) {
|
||
break 2;
|
||
}
|
||
|
||
$data = (array) ($block['data'] ?? []);
|
||
$key = (string) ($data['key'] ?? '');
|
||
|
||
if (($block['type'] ?? null) === 'issue') {
|
||
$sources['anliegen'] = 'Anliegen';
|
||
$sources['unteranliegen'] = 'Unteranliegen';
|
||
} elseif (($block['type'] ?? null) === 'field' && isset($catalog[$key]) && $catalog[$key]->type->canControl()) {
|
||
$sources[$key] = (string) (($data['label'] ?? '') ?: $catalog[$key]->label);
|
||
}
|
||
}
|
||
}
|
||
|
||
return $sources;
|
||
}
|
||
|
||
/**
|
||
* @param array<string, mixed> $editor
|
||
* @return array<string, string>
|
||
*/
|
||
private static function sourceValues(array $editor, string $source): array
|
||
{
|
||
if ($source === 'anliegen' || $source === 'unteranliegen') {
|
||
$only = self::inventory($editor)['issues'];
|
||
$options = [];
|
||
|
||
foreach (InquiryIssue::tree() as $issue) {
|
||
if ($only !== [] && ! in_array($issue['key'], $only, true)) {
|
||
continue;
|
||
}
|
||
|
||
if ($source === 'anliegen') {
|
||
$options[$issue['key']] = $issue['label'];
|
||
|
||
continue;
|
||
}
|
||
|
||
foreach ($issue['children'] as $child) {
|
||
$options[$child['key']] = $issue['label'].' › '.$child['label'];
|
||
}
|
||
}
|
||
|
||
return $options;
|
||
}
|
||
|
||
return self::fieldValues($source);
|
||
}
|
||
|
||
/**
|
||
* @return array<string, string>
|
||
*/
|
||
private static function fieldValues(string $key): array
|
||
{
|
||
$field = InquiryField::query()->where('key', $key)->first();
|
||
|
||
if ($field === null || ! in_array($field->type, [FieldType::Select, FieldType::Multiselect, FieldType::Boolean], true)) {
|
||
return [];
|
||
}
|
||
|
||
return collect($field->optionList())->pluck('label', 'key')->all();
|
||
}
|
||
}
|