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:
1 parent
2ee1fc9866
commit
c6a8167601
45 files changed
+5415
No files matched your search
@@ -0,0 +1,143 @@
|
||||
<?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;
|
||||
|
||||
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}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Communication\Entries\Pages;
|
||||
|
||||
use App\Domain\Communication\InquiryEntry;
|
||||
use App\Domain\Communication\InquiryTemplate;
|
||||
use App\Domain\Communication\Keys;
|
||||
use App\Filament\Resources\Communication\Entries\InquiryEntryResource;
|
||||
use App\Filament\Support\ListsCatalog;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class ListInquiryEntries extends ListRecords
|
||||
{
|
||||
use ListsCatalog;
|
||||
|
||||
protected static string $resource = InquiryEntryResource::class;
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return 'Ein Anfrage-Einstieg ist die Nutzungsvariante einer Anfragevorlage: zugelassene Anliegen, Vorauswahl, Texte und Darstellung. Nur veröffentlichte Einstiege lassen sich im CMS mit dem Widget „Anfrage“ auf einer Seite einbinden. Mehrere Seiten können denselben Einstieg verwenden.';
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('create')
|
||||
->label('Einstieg anlegen')
|
||||
->modalHeading('Neuer Anfrage-Einstieg')
|
||||
->modalDescription('Zugelassene Anliegen, Vorauswahl und Texte legst du danach fest.')
|
||||
->modalSubmitActionLabel('Einstieg anlegen')
|
||||
->schema([
|
||||
TextInput::make('name')->label('Bezeichnung')->required()->maxLength(120),
|
||||
Select::make('template_id')->label('Anfragevorlage')->required()
|
||||
->options(fn (): array => InquiryTemplate::query()->whereNull('archived_at')->orderBy('name')->pluck('name', 'id')->all()),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$entry = InquiryEntry::query()->create([
|
||||
'key' => Keys::from($data['name'], InquiryEntry::query()->pluck('key')->all()),
|
||||
'name' => $data['name'],
|
||||
'template_id' => $data['template_id'],
|
||||
'config' => InquiryEntry::emptyConfig(),
|
||||
]);
|
||||
|
||||
Notification::make()->title('Der Einstieg ist angelegt.')->success()->send();
|
||||
$this->redirect(InquiryEntryResource::getUrl('edit', ['record' => $entry]));
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
protected function catalogRows(): array
|
||||
{
|
||||
$rows = [];
|
||||
|
||||
foreach (InquiryEntry::query()->with('template.publishedVersion')->orderBy('name')->get() as $entry) {
|
||||
$url = InquiryEntryResource::getUrl('edit', ['record' => $entry]);
|
||||
$archived = $entry->archived_at !== null;
|
||||
$live = $entry->isLive();
|
||||
$config = (array) ($entry->published_config ?? $entry->config);
|
||||
$mode = ($config['mode'] ?? 'compact') === 'wizard' ? 'Mehrstufiger Dialog' : 'Kompaktformular';
|
||||
|
||||
$rows[] = [
|
||||
'schluessel' => 'e'.$entry->id,
|
||||
'titel' => $entry->name,
|
||||
'meta' => 'Anfrage-Einstieg · '.$mode.' · Vorlage „'.$entry->template->name.'“',
|
||||
'text' => '',
|
||||
'symbol' => 'modul',
|
||||
'url' => $url,
|
||||
'chips' => array_values(array_filter([
|
||||
$archived ? ['label' => 'Archiviert', 'ton' => 'leise'] : ($live
|
||||
? ['label' => 'Veröffentlicht', 'ton' => 'gut']
|
||||
: ($entry->published_at !== null ? ['label' => 'Veröffentlicht, aber Vorlage nicht gültig', 'ton' => 'achtung'] : ['label' => 'Entwurf', 'ton' => 'offen'])),
|
||||
$entry->published_at !== null && $entry->hasUnpublishedChanges() ? ['label' => 'Änderungen noch nicht veröffentlicht', 'ton' => 'achtung'] : null,
|
||||
])),
|
||||
'zustand' => [$archived ? 'archiviert' : ($live ? 'veroeffentlicht' : 'entwurf'), ...($entry->published_at !== null && $entry->hasUnpublishedChanges() ? ['aenderungen'] : [])],
|
||||
'aktionen' => [['label' => 'Bearbeiten', 'href' => $url, 'icon' => 'stift']],
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
protected function zustandOptionen(): array
|
||||
{
|
||||
return [
|
||||
'alle' => 'Jeder Zustand',
|
||||
'veroeffentlicht' => 'Veröffentlicht',
|
||||
'entwurf' => 'Entwurf',
|
||||
'aenderungen' => 'Mit unveröffentlichten Änderungen',
|
||||
'archiviert' => 'Archiviert',
|
||||
];
|
||||
}
|
||||
|
||||
protected function suchPlatzhalter(): string
|
||||
{
|
||||
return 'Bezeichnung';
|
||||
}
|
||||
|
||||
protected function einheit(): array
|
||||
{
|
||||
return ['Anfrage-Einstieg', 'Anfrage-Einstiege'];
|
||||
}
|
||||
|
||||
protected function leer(): array
|
||||
{
|
||||
return ['titel' => 'Noch keine Anfrage-Einstiege', 'text' => 'Mit „Einstieg anlegen“ oben entsteht der erste Einstieg. Dazu braucht es eine veröffentlichte Anfragevorlage.'];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user