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>
116 lines
3.6 KiB
PHP
116 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Cms;
|
|
|
|
use App\Domain\Cms\Widgets\WidgetRegistry;
|
|
use App\Jobs\PublishPublicMedia;
|
|
use App\Models\User;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class PageService
|
|
{
|
|
public function __construct(private readonly WidgetRegistry $widgets) {}
|
|
|
|
/**
|
|
* Speichert einen Entwurf als neue Revision. Veröffentlicht nichts.
|
|
*
|
|
* @param array<int|string, mixed> $blocks Bausteine im Altformat oder als Widget-Hülle
|
|
*/
|
|
public function saveRevision(Page $page, array $blocks, ?string $seoTitle, ?string $seoDescription, ?User $author): PageRevision
|
|
{
|
|
return $this->storeRevision($page, $this->widgets->normalize($blocks), $seoTitle, $seoDescription, $author);
|
|
}
|
|
|
|
public function publish(Page $page, PageRevision $revision): void
|
|
{
|
|
if ($revision->page_id !== $page->id) {
|
|
throw ValidationException::withMessages([
|
|
'revision' => 'Die Revision gehört zu einer anderen Seite.',
|
|
]);
|
|
}
|
|
|
|
$page->published_revision_id = $revision->id;
|
|
$page->save();
|
|
}
|
|
|
|
/**
|
|
* Legt den Stand einer früheren Revision unverändert als neue Revision an. Die gespeicherten Bausteine
|
|
* werden nicht umgeschrieben; ältere Formate werden erst beim Lesen angehoben.
|
|
*/
|
|
public function restore(Page $page, PageRevision $source, ?User $author): PageRevision
|
|
{
|
|
if ($source->page_id !== $page->id) {
|
|
throw ValidationException::withMessages([
|
|
'revision' => 'Die Revision gehört zu einer anderen Seite.',
|
|
]);
|
|
}
|
|
|
|
return $this->storeRevision(
|
|
$page,
|
|
$source->blocks ?? [],
|
|
$source->seo_title,
|
|
$source->seo_description,
|
|
$author,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Normalisiert den Pfad und prüft, dass keine andere Seite ihn verwendet.
|
|
*/
|
|
public function availablePath(string $path, ?Page $except = null): string
|
|
{
|
|
$path = $this->normalizePath($path);
|
|
|
|
$taken = Page::query()
|
|
->where('path', $path)
|
|
->when($except !== null, fn ($query) => $query->whereKeyNot($except->getKey()))
|
|
->exists();
|
|
|
|
if ($taken) {
|
|
throw ValidationException::withMessages([
|
|
'path' => 'Diesen Pfad verwendet bereits eine andere Seite.',
|
|
]);
|
|
}
|
|
|
|
return $path;
|
|
}
|
|
|
|
public function normalizePath(string $path): string
|
|
{
|
|
$path = '/'.trim($path, '/');
|
|
|
|
if ($path === '/') {
|
|
return '/';
|
|
}
|
|
|
|
$path = mb_strtolower($path);
|
|
|
|
if (preg_match('#^/[a-z0-9]+(?:-[a-z0-9]+)*$#', $path) !== 1) {
|
|
throw ValidationException::withMessages([
|
|
'path' => 'Der Pfad darf nur Kleinbuchstaben, Ziffern und Bindestriche enthalten.',
|
|
]);
|
|
}
|
|
|
|
return $path;
|
|
}
|
|
|
|
/**
|
|
* @param array<int|string, mixed> $blocks
|
|
*/
|
|
private function storeRevision(Page $page, array $blocks, ?string $seoTitle, ?string $seoDescription, ?User $author): PageRevision
|
|
{
|
|
$revision = $page->revisions()->create([
|
|
'blocks' => array_values($blocks),
|
|
'seo_title' => $seoTitle !== null && $seoTitle !== '' ? $seoTitle : null,
|
|
'seo_description' => $seoDescription !== null && $seoDescription !== '' ? $seoDescription : null,
|
|
'created_by' => $author?->id,
|
|
]);
|
|
|
|
foreach ($this->widgets->mediaPaths($revision->blocks) as $path) {
|
|
PublishPublicMedia::dispatch($path);
|
|
}
|
|
|
|
return $revision;
|
|
}
|
|
}
|