Führe eine zentrale Widget-Registry mit visuellem Seiteneditor ein.
CI Feature / test (push) Successful in 31s

- Codebasiertes Widget-Register (config/cms.php) mit Vertrag
  {id, type, v, variant, settings, data, refs}: Typkennung, Schemaversion,
  Prüfregeln, freigegebene Varianten, Editorfelder, Blade-Ansicht,
  Verweisauflösung und Medienliste je Widget-Art.
- Die sechs Bestandsbausteine bleiben als Version 1 lesbar; gespeicherte
  Revisionen werden nicht umgeschrieben, sondern beim Lesen angehoben
  (Bild und Text: Version 2 mit Titel, formatiertem Text, Bild links/rechts).
  Wiederherstellen kopiert eine Revision unverändert.
- Neue Widgets: Einstieg (Hero) und Programm-/Modulkarten. Letztere speichern
  nur Verweise; Titel und Kurzbeschreibung kommen aus den Fachdaten. Öffentlich
  erscheinen nur Programme mit Anzeigefreigabe (gleiche Regel wie /programme,
  jetzt in PublicCatalogReader); Module nur in der Redaktionsvorschau, bis
  öffentliche Profile (ADR-29) bestehen.
- Ein Renderer für öffentliche Seite, Vorschau und Blockvorschau im Editor.
- Seiteneditor als Filament-Builder: Auswahl mit Beschreibung und Schema,
  kompakte Abschnitte mit Vorschau, Bearbeitung im Dialog, Sortieren,
  Duplizieren. Speichern erzeugt nur einen Entwurf.
- Vorschau einer Revision in 390/768/1440 px; Vorschauroute nutzt den
  Personal-Guard (vorher war sie für Redakteure ohne Mitgliedersitzung
  nicht erreichbar).
- Basislayout in Komponenten (Marke, Kopf, Fuß, Seitenvorlage).
- Navigation: bearbeiten, ausblenden, löschen, per Ziehen sortieren;
  unsichere Adressen (javascript:) werden abgewiesen und nicht ausgegeben.
  Ergänzende Migration is_visible (Vorgabe sichtbar).
- Pfadfehler und doppelte Pfade erscheinen am Pfadfeld statt still zu scheitern.

Tests: BlockRegistryTest geht in WidgetRegistryTest auf (gleiche Prüfungen
plus Registrierung, Versionierung, Bereinigung). Bestandsseiten werden gegen
Textfixtures aus dem Stand vor der Umstellung geprüft.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-17 17:49:30 +01:00
1 parent cfdd6de0c7
commit 9d936bfa4a
76 files changed
+4237 -475

No files matched your search

+31 -73
View File
@@ -3,20 +3,17 @@
namespace App\Filament\Resources\Pages;
use App\Domain\Catalog\Pillar;
use App\Domain\Cms\Blocks\BlockRegistry;
use App\Domain\Cms\Page;
use App\Filament\Resources\Pages\Pages\CreatePage;
use App\Filament\Resources\Pages\Pages\EditPage;
use App\Filament\Resources\Pages\Pages\ListPages;
use App\Filament\Resources\Pages\RelationManagers\RevisionsRelationManager;
use App\Filament\Support\WidgetEditor;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Resource;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
@@ -35,76 +32,37 @@ class PageResource extends Resource
public static function form(Schema $schema): Schema
{
$labels = app(BlockRegistry::class)->labels();
return $schema->components([
TextInput::make('path')
->label('Pfad')
->required()
->maxLength(255)
->helperText('Zum Beispiel / oder /praevention'),
TextInput::make('seo_title')
->label('SEO-Titel')
->maxLength(255),
Textarea::make('seo_description')
->label('SEO-Beschreibung')
->maxLength(500)
->columnSpanFull(),
CheckboxList::make('pillars')
->label('Fachliche Säulen')
->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all())
->helperText('Eine veröffentlichte Seite erscheint auf den gewählten Themenbereichen der Website. Eine Seite kann mehreren Säulen zugeordnet sein.')
->columns(1),
Repeater::make('blocks')
->label('Bausteine')
->schema([
Select::make('type')
->label('Typ')
->options($labels)
->required()
->live(),
TextInput::make('heading')
->label('Überschrift')
->visible(fn (Get $get): bool => in_array($get('type'), ['heading', 'call_to_action'], true)),
Textarea::make('intro')
->label('Einleitung')
->visible(fn (Get $get): bool => $get('type') === 'heading'),
Textarea::make('body')
->label('Text')
->visible(fn (Get $get): bool => in_array($get('type'), ['prose', 'image_text'], true))
->columnSpanFull(),
FileUpload::make('image')
->label('Bild')
->disk('cms_incoming')
->directory('cms')
->image()
->visible(fn (Get $get): bool => $get('type') === 'image_text'),
TextInput::make('alt')
->label('Alternativtext')
->visible(fn (Get $get): bool => $get('type') === 'image_text'),
Textarea::make('text')
->label('Text')
->visible(fn (Get $get): bool => $get('type') === 'call_to_action'),
TextInput::make('label')
->label('Beschriftung der Aktion')
->visible(fn (Get $get): bool => $get('type') === 'call_to_action'),
TextInput::make('url')
->label('Adresse')
->visible(fn (Get $get): bool => $get('type') === 'call_to_action'),
Repeater::make('items')
->label('Einträge')
->visible(fn (Get $get): bool => in_array($get('type'), ['cards', 'faq'], true))
->schema([
TextInput::make('title')->label('Titel')->visible(fn (Get $get): bool => $get('../../type') === 'cards'),
Textarea::make('text')->label('Text')->visible(fn (Get $get): bool => $get('../../type') === 'cards'),
TextInput::make('url')->label('Adresse')->visible(fn (Get $get): bool => $get('../../type') === 'cards'),
TextInput::make('question')->label('Frage')->visible(fn (Get $get): bool => $get('../../type') === 'faq'),
Textarea::make('answer')->label('Antwort')->visible(fn (Get $get): bool => $get('../../type') === 'faq'),
]),
])
Section::make('Seite und Suchmaschinen')
->description('Adresse, Titel für Suchmaschinen und Zuordnung zu Themenbereichen.')
->collapsible()
->columns(2)
->columnSpanFull()
->reorderable()
->collapsed(),
->schema([
TextInput::make('path')
->label('Pfad')
->required()
->maxLength(255)
->helperText('Zum Beispiel / oder /praevention'),
TextInput::make('seo_title')
->label('SEO-Titel')
->maxLength(255),
Textarea::make('seo_description')
->label('SEO-Beschreibung')
->maxLength(500)
->columnSpanFull(),
CheckboxList::make('pillars')
->label('Fachliche Säulen')
->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all())
->helperText('Eine veröffentlichte Seite erscheint auf den gewählten Themenbereichen der Website. Eine Seite kann mehreren Säulen zugeordnet sein.')
->columns(1),
]),
Section::make('Inhalt der Seite')
->description('Abschnitte hinzufügen, per Klick auf die Vorschau bearbeiten, mit den Pfeilen sortieren. Speichern legt einen Entwurf an; veröffentlicht wird erst über „Veröffentlichen“.')
->columnSpanFull()
->schema([
WidgetEditor::builder('blocks'),
]),
]);
}
@@ -5,31 +5,51 @@
use App\Domain\Cms\Page;
use App\Domain\Cms\PageService;
use App\Filament\Resources\Pages\PageResource;
use App\Filament\Support\WidgetEditor;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException;
class CreatePage extends CreateRecord
{
protected static string $resource = PageResource::class;
protected static bool $canCreateAnother = false;
/**
* @param array<string, mixed> $data
*/
protected function handleRecordCreation(array $data): Model
{
$service = app(PageService::class);
$page = Page::query()->create([
'path' => $service->normalizePath($data['path']),
]);
$blocks = WidgetEditor::fromBuilderState($data['blocks'] ?? []);
$service->saveRevision(
$page,
$data['blocks'] ?? [],
$data['seo_title'] ?? null,
$data['seo_description'] ?? null,
auth()->user(),
);
try {
return DB::transaction(function () use ($service, $data, $blocks): Page {
$page = Page::query()->create([
'path' => $service->availablePath($data['path']),
]);
return $page;
$service->saveRevision(
$page,
$blocks,
$data['seo_title'] ?? null,
$data['seo_description'] ?? null,
auth()->user(),
);
return $page;
});
} catch (ValidationException $exception) {
throw ValidationException::withMessages(
WidgetEditor::mapErrors($exception->errors(), array_keys($this->data['blocks'] ?? [])),
);
}
}
protected function getRedirectUrl(): string
{
return static::getResource()::getUrl('edit', ['record' => $this->getRecord()]);
}
}
+42 -11
View File
@@ -6,9 +6,12 @@
use App\Domain\Cms\Page;
use App\Domain\Cms\PageService;
use App\Filament\Resources\Pages\PageResource;
use App\Filament\Support\WidgetEditor;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\ValidationException;
class EditPage extends EditRecord
{
@@ -19,27 +22,52 @@ protected function getHeaderActions(): array
return [
Action::make('preview')
->label('Vorschau')
->icon('heroicon-o-device-phone-mobile')
->color('gray')
->tooltip('Zuletzt gespeicherten Entwurf in Smartphone-, Tablet- und Desktopbreite ansehen')
->url(function (): string {
$revision = $this->record->latestRevision;
return $revision === null
? '#'
: route('pages.preview', $revision);
: route('pages.preview.devices', $revision);
})
->openUrlInNewTab(),
Action::make('publish')
->label('Veröffentlichen')
->icon('heroicon-o-globe-alt')
->requiresConfirmation()
->modalHeading('Zuletzt gespeicherten Entwurf veröffentlichen?')
->modalDescription(fn (): string => 'Veröffentlicht wird Revision Nr. '.($this->record->latestRevision?->id ?? '–').'. Noch nicht gespeicherte Änderungen werden nicht veröffentlicht.')
->visible(fn (): bool => auth()->user()?->can('publish', $this->record) ?? false)
->action(function (PageService $service): void {
$revision = $this->record->latestRevision;
abort_if($revision === null, 404);
$service->publish($this->record, $revision);
$this->record->refresh();
Notification::make()->title('Seite veröffentlicht')->success()->send();
}),
Action::make('open')
->label('Live-Seite')
->icon('heroicon-o-arrow-top-right-on-square')
->color('gray')
->visible(fn (): bool => $this->record->isPublished())
->url(fn (): string => $this->record->publicUrl())
->openUrlInNewTab(),
];
}
protected function getSaveFormAction(): Action
{
return parent::getSaveFormAction()->label('Entwurf speichern');
}
protected function getSavedNotificationTitle(): ?string
{
return 'Entwurf gespeichert. Die Live-Seite bleibt unverändert, bis Sie veröffentlichen.';
}
/**
* @param array<string, mixed> $data
* @return array<string, mixed>
@@ -47,7 +75,7 @@ protected function getHeaderActions(): array
protected function mutateFormDataBeforeFill(array $data): array
{
$revision = $this->record->latestRevision ?? $this->record->publishedRevision;
$data['blocks'] = $revision?->blocks ?? [];
$data['blocks'] = WidgetEditor::toBuilderState($revision?->blocks);
$data['seo_title'] = $revision?->seo_title;
$data['seo_description'] = $revision?->seo_description;
$data['pillars'] = $this->record->pillars()->pluck('pillars.id')->all();
@@ -62,19 +90,22 @@ protected function handleRecordUpdate(Model $record, array $data): Model
{
/** @var Page $record */
$service = app(PageService::class);
$blocks = WidgetEditor::fromBuilderState($data['blocks'] ?? []);
try {
$path = $service->availablePath($data['path'], $record);
$service->saveRevision($record, $blocks, $data['seo_title'] ?? null, $data['seo_description'] ?? null, auth()->user());
} catch (ValidationException $exception) {
throw ValidationException::withMessages(
WidgetEditor::mapErrors($exception->errors(), array_keys($this->data['blocks'] ?? [])),
);
}
$record->update([
'path' => $service->normalizePath($data['path']),
'path' => $path,
]);
app(PillarService::class)->assignPages($record, array_map(intval(...), $data['pillars'] ?? []));
$service->saveRevision(
$record,
$data['blocks'] ?? [],
$data['seo_title'] ?? null,
$data['seo_description'] ?? null,
auth()->user(),
);
return $record;
}
}
@@ -4,7 +4,9 @@
use App\Domain\Cms\PageRevision;
use App\Domain\Cms\PageService;
use App\Filament\Resources\Pages\PageResource;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
@@ -22,11 +24,22 @@ public function table(Table $table): Table
TextColumn::make('id')->label('Nr.'),
TextColumn::make('created_at')->label('Gespeichert')->dateTime('d.m.Y H:i'),
TextColumn::make('author.name')->label('Von'),
TextColumn::make('sections')
->label('Abschnitte')
->state(fn (PageRevision $record): int => count($record->widgets())),
TextColumn::make('published')
->label('Live')
->badge()
->color(fn (string $state): string => $state === 'Ja' ? 'success' : 'gray')
->state(fn (PageRevision $record): string => $record->id === $this->getOwnerRecord()->published_revision_id ? 'Ja' : 'Nein'),
])
->recordActions([
Action::make('preview')
->label('Vorschau')
->icon('heroicon-o-eye')
->color('gray')
->url(fn (PageRevision $record): string => route('pages.preview.devices', $record))
->openUrlInNewTab(),
Action::make('publish')
->label('Veröffentlichen')
->requiresConfirmation()
@@ -34,13 +47,16 @@ public function table(Table $table): Table
->action(function (PageRevision $record, PageService $service): void {
$service->publish($this->getOwnerRecord(), $record);
$this->getOwnerRecord()->refresh();
Notification::make()->title('Revision '.$record->id.' ist jetzt live.')->success()->send();
}),
Action::make('restore')
->label('Wiederherstellen')
->requiresConfirmation()
->modalDescription('Es entsteht eine neue Revision. Die Live-Seite bleibt unverändert, bis sie veröffentlicht wird.')
->modalDescription('Es entsteht eine neue Revision mit diesem Stand. Die Live-Seite bleibt unverändert, bis sie veröffentlicht wird.')
->action(function (PageRevision $record, PageService $service): void {
$service->restore($this->getOwnerRecord(), $record, auth()->user());
$restored = $service->restore($this->getOwnerRecord(), $record, auth()->user());
Notification::make()->title('Als neue Revision '.$restored->id.' wiederhergestellt.')->success()->send();
$this->redirect(PageResource::getUrl('edit', ['record' => $this->getOwnerRecord()]));
}),
])
->defaultSort('id', 'desc');