CI Feature / test (push) Successful in 4m17s
Der Editor zeigt Bereiche mit Feldern und Teilbereichen; Felder werden direkt im Bereich angelegt oder aus dem Katalog übernommen und landen im selben Katalog wie bisher. Bedingungen stehen am Feld, Teilbereich oder Bereich und werden zu denselben Regeln wie die Regelliste; alles andere bleibt unter „Weitere Regeln“. Navigation: Anfragen, Formulare & Befragungen, Einstellungen. Anliegen, Feldkatalog, Feldgruppen und Einstiege bleiben erreichbar (Einstellungen). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
150 lines
7.7 KiB
PHP
150 lines
7.7 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Resources\Communication\Entries;
|
||
|
||
use App\Domain\Communication\FormTexts;
|
||
use App\Domain\Communication\InquiryEntry;
|
||
use App\Domain\Communication\InquiryField;
|
||
use App\Domain\Communication\InquiryIssue;
|
||
use App\Domain\Communication\InquiryTemplate;
|
||
use App\Filament\Resources\Communication\CommunicationResource;
|
||
use App\Filament\Resources\Communication\Entries\Pages\EditInquiryEntry;
|
||
use App\Filament\Resources\Communication\Entries\Pages\ListInquiryEntries;
|
||
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\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;
|
||
|
||
/**
|
||
* Anfrage-Einstiege: die veröffentlichbare Nutzungsvariante einer Anfragevorlage. Sie legen fest, welche Anliegen
|
||
* angeboten werden, was vorausgewählt ist, welche Texte erscheinen und ob ein Kompaktformular oder ein mehrstufiger
|
||
* Dialog gezeigt wird. Das CMS wählt nur einen veröffentlichten Einstieg aus.
|
||
*/
|
||
class InquiryEntryResource extends CommunicationResource
|
||
{
|
||
protected static ?string $model = InquiryEntry::class;
|
||
|
||
protected static ?string $navigationLabel = 'Anfrage-Einstiege';
|
||
|
||
protected static ?string $modelLabel = 'Anfrage-Einstieg';
|
||
|
||
protected static ?string $pluralModelLabel = 'Anfrage-Einstiege';
|
||
|
||
protected static ?string $recordTitleAttribute = 'name';
|
||
|
||
protected static ?string $slug = 'kommunikation/einstiege';
|
||
|
||
protected static ?int $navigationSort = 6;
|
||
|
||
/** Technischer Baustein des Formular-Editors: erreichbar über „Einstellungen“, nicht in der Hauptnavigation (ADR-61). */
|
||
public static function shouldRegisterNavigation(): bool
|
||
{
|
||
return false;
|
||
}
|
||
|
||
public static function form(Schema $schema): Schema
|
||
{
|
||
return $schema->components([
|
||
TextInput::make('name')->label('Bezeichnung')->required()->maxLength(120)
|
||
->helperText('So heißt der Einstieg in der Auswahl im CMS, zum Beispiel „Kurse & Workshops“.'),
|
||
Select::make('template_id')->label('Anfragevorlage')->required()->live()
|
||
->options(fn (): array => InquiryTemplate::query()->whereNull('archived_at')->orderBy('name')->pluck('name', 'id')->all())
|
||
->helperText('Die Formularstruktur kommt aus der veröffentlichten Fassung dieser Vorlage und folgt jeder neu veröffentlichten Fassung.'),
|
||
Section::make('Angebotene Anliegen')->description('Der Rahmen, in dem Besucher wählen. Ist nur ein Anliegen zugelassen, müssen sie es nicht bestätigen.')->schema([
|
||
Select::make('config.allowed_issues')->label('Zugelassene Anliegen')->multiple()
|
||
->options(fn (): array => InquiryIssue::query()->offered()->whereNull('parent_id')->orderBy('sort_order')->pluck('label', 'key')->all())
|
||
->helperText('Leer: alle Anliegen der Vorlage.'),
|
||
Select::make('config.allowed_subissues')->label('Zugelassene Unteranliegen')->multiple()
|
||
->options(function (): array {
|
||
$options = [];
|
||
|
||
foreach (InquiryIssue::tree() as $issue) {
|
||
foreach ($issue['children'] as $child) {
|
||
$options[$child['key']] = $issue['label'].' › '.$child['label'];
|
||
}
|
||
}
|
||
|
||
return $options;
|
||
})
|
||
->helperText('Leer: alle Unteranliegen der zugelassenen Anliegen.'),
|
||
Repeater::make('config.preselect')
|
||
->label('Vorauswahl')
|
||
->helperText('Zum Beispiel das Kursformat „Schul-AG“. Besucher können die Auswahl ändern.')
|
||
->schema([
|
||
Select::make('field')->label('Angabe')->required()->live()->searchable()->distinct()
|
||
->options(fn (): array => ['anliegen' => 'Anliegen', 'unteranliegen' => 'Unteranliegen'] + InquiryField::query()->offered()->whereIn('type', ['select', 'boolean'])->orderBy('name')->pluck('name', 'key')->all()),
|
||
Select::make('value')->label('Wert')->required()
|
||
->options(function (Get $get): array {
|
||
$field = (string) $get('field');
|
||
|
||
if ($field === 'anliegen') {
|
||
return InquiryIssue::query()->offered()->whereNull('parent_id')->orderBy('sort_order')->pluck('label', 'key')->all();
|
||
}
|
||
|
||
if ($field === 'unteranliegen') {
|
||
return InquiryIssue::query()->offered()->whereNotNull('parent_id')->orderBy('sort_order')->pluck('label', 'key')->all();
|
||
}
|
||
|
||
$model = InquiryField::query()->where('key', $field)->first();
|
||
|
||
return $model === null ? [] : collect($model->optionList())->pluck('label', 'key')->all();
|
||
}),
|
||
])
|
||
->addActionLabel('Vorauswahl hinzufügen')
|
||
->itemLabel(fn (array $state): ?string => ($state['field'] ?? null) ? ($state['field'] === 'anliegen' ? 'Anliegen' : ($state['field'] === 'unteranliegen' ? 'Unteranliegen' : InquiryField::query()->where('key', $state['field'])->value('name'))) : null),
|
||
]),
|
||
Section::make('Darstellung')->schema([
|
||
Select::make('config.mode')->label('Formularart')->required()->default('compact')
|
||
->options(['compact' => 'Kompaktformular: alle Fragen auf einer Seite', 'wizard' => 'Mehrstufiger Dialog: Schritt für Schritt mit Zusammenfassung'])
|
||
->helperText('Beides verwendet dieselbe Vorlage, dieselben Bedingungen und dieselbe Prüfung.'),
|
||
Select::make('config.open')->label('Beim Aufruf der Seite')->required()->default('inline')
|
||
->options(['inline' => 'Formular direkt anzeigen', 'button' => 'Zunächst nur eine Schaltfläche zeigen, die das Formular öffnet']),
|
||
]),
|
||
Section::make('Texte dieses Einstiegs')
|
||
->description('Überschreibt einzelne Texte der Vorlage. Leer lassen: es gilt der Text der Vorlage. Die Texte werden ausschließlich hier und in der Vorlage gepflegt, nie im CMS.')
|
||
->collapsed()
|
||
->schema(self::textFields()),
|
||
Placeholder::make('key_info')->label('Interne Kennung')->content(fn (?InquiryEntry $record): string => (string) $record?->key)
|
||
->visible(fn (?InquiryEntry $record): bool => $record !== null),
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* @return list<Component>
|
||
*/
|
||
private static function textFields(): array
|
||
{
|
||
$fields = [];
|
||
|
||
foreach (FormTexts::FIELDS as $key => [$label, $default, $help, $multiline]) {
|
||
$field = $multiline
|
||
? Textarea::make("config.texts.$key")->rows(2)->maxLength(1500)
|
||
: TextInput::make("config.texts.$key")->maxLength(200);
|
||
|
||
$fields[] = $field->label($label)->placeholder('Text der Vorlage'.($default !== '' ? ': '.$default : ''))->helperText($help);
|
||
}
|
||
|
||
return $fields;
|
||
}
|
||
|
||
public static function table(Table $table): Table
|
||
{
|
||
return $table->columns([TextColumn::make('name')->label('Bezeichnung')]);
|
||
}
|
||
|
||
public static function getPages(): array
|
||
{
|
||
return [
|
||
'index' => ListInquiryEntries::route('/'),
|
||
'edit' => EditInquiryEntry::route('/{record}'),
|
||
];
|
||
}
|
||
}
|