Führe Abschnitte mit Raster, gemeinsames Designsystem und globales Website-Gerüst ein.
CI Feature / test (push) Failing after 20s

- Seite → Abschnitte → Plätze → Widgets: sechs Raster mit höchstens vier Einheiten,
  Hintergrund, Breite, Abstand und Trenner als Aufzählungswerte; je Platz ein Widget
  aus dem bestehenden Register. Neue Spalte page_revisions.sections (ergänzend);
  blocks erhält weiterhin alle Widgets in Lesereihenfolge als Rollback-Fassung.
- Widgets erhalten Mindest- und Vorzugsbreite; Darstellung über Container-Abfragen.
- Editor: Abschnitts-Repeater mit grafischer Rasterauswahl, Plätzen im Rasterverhältnis,
  breiter Arbeitsfläche, kompakten Vorschauen ohne Bildlaufleiste, Meldungen mit
  Abschnitt und Platz; Rasterwechsel entfernt nie ein Widget. Seite duplizieren.
- Designsystem: Marken- und Bedeutungs-Tokens (vorläufig), gemeinsame Grundkomponenten,
  Nunito/Source Sans 3 lokal; Mitgliederbereich nutzt dieselben Tokens und die Wortmarke.
- Kopfzeile, mobile Navigation, Untermenü (parent_id, ergänzend), Fußbereichsgruppen,
  vorbereiteter Warenkorbzugang (abgeschaltet). Öffentliche Seiten gleich für alle Besucher.
- cms:revert-published als Wiederherstellungsweg vor einem Code-Rollback.

Die Editor-Tests der ersten Iteration sind bewusst auf den neuen Formularzustand
(sections statt blocks) umgestellt; ihre Prüfungen gelten unverändert für die Widgets.
Der Vorschautest erwartet keine anmeldeabhängige Kopfzeile mehr (ADR-32).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-17 20:34:06 +01:00
1 parent db4bd30319
commit 480d55989b
57 files changed
+4730 -818

No files matched your search

+54 -2
View File
@@ -6,12 +6,25 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class NavigationItem extends Model
{
/**
* Plätze im globalen Website-Gerüst. Die drei Fußbereichsgruppen ersetzen eine eigene Footer-Verwaltung.
*/
public const PLACEMENTS = [
'header' => 'Kopfzeile',
'footer' => 'Fußzeile',
'header' => 'Kopfzeile (Hauptnavigation)',
'footer' => 'Fußbereich: Service',
'footer_contact' => 'Fußbereich: Kontakt',
'footer_legal' => 'Fußbereich: Rechtliches',
];
/** Spaltenüberschriften im Fußbereich. */
public const FOOTER_GROUPS = [
'footer' => 'Service',
'footer_contact' => 'Kontakt',
'footer_legal' => 'Rechtliches',
];
protected $fillable = [
@@ -21,8 +34,19 @@ class NavigationItem extends Model
'placement',
'sort_order',
'is_visible',
'parent_id',
];
protected static function booted(): void
{
// Untermenüs gibt es nur in der Hauptnavigation.
static::saving(function (NavigationItem $item): void {
if ($item->placement !== 'header' && $item->getAttribute('parent_id') !== null) {
$item->parent_id = null;
}
});
}
protected function casts(): array
{
return [
@@ -35,6 +59,16 @@ public function page(): BelongsTo
return $this->belongsTo(Page::class);
}
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
}
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id')->orderBy('sort_order')->orderBy('id');
}
/**
* @param Builder<NavigationItem> $query
*/
@@ -59,4 +93,22 @@ public function href(): ?string
return $this->url;
}
/**
* Pfad des Ziels innerhalb der Website (für die Kennzeichnung des aktiven Eintrags); null bei externen Zielen.
*/
public function targetPath(): ?string
{
if ($this->page !== null) {
return $this->page->path;
}
if (is_string($this->url) && str_starts_with($this->url, '/') && ! str_starts_with($this->url, '//')) {
$path = parse_url($this->url, PHP_URL_PATH);
return is_string($path) ? '/'.trim($path, '/') : null;
}
return null;
}
}
+17 -4
View File
@@ -2,7 +2,7 @@
namespace App\Domain\Cms;
use App\Domain\Cms\Widgets\WidgetRegistry;
use App\Domain\Cms\Sections\PageSections;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -14,6 +14,7 @@ class PageRevision extends Model
protected $fillable = [
'page_id',
'blocks',
'sections',
'seo_title',
'seo_description',
'created_by',
@@ -23,6 +24,7 @@ protected function casts(): array
{
return [
'blocks' => 'array',
'sections' => 'array',
'created_at' => 'datetime',
];
}
@@ -38,13 +40,24 @@ public function author(): BelongsTo
}
/**
* Bausteine als aktuelle Widget-Hüllen. Die gespeicherten Daten bleiben unverändert.
* Abschnitte als aktuelle Hüllen. Revisionen ohne Abschnitte (vor Einführung des Rasters) werden als
* einspaltige Abschnitte gelesen. Die gespeicherten Daten bleiben unverändert.
*
* @return list<array<string, mixed>>
*/
public function sections(): array
{
return app(PageSections::class)->read($this->sections, $this->blocks);
}
/**
* Widgets in Lesereihenfolge als aktuelle Hüllen.
*
* @return list<array<string, mixed>>
*/
public function widgets(): array
{
return app(WidgetRegistry::class)->read($this->blocks);
return app(PageSections::class)->flatten($this->sections());
}
/**
@@ -52,6 +65,6 @@ public function widgets(): array
*/
public function contentTitle(): ?string
{
return app(WidgetRegistry::class)->pageTitle($this->blocks);
return app(PageSections::class)->pageTitle($this->sections());
}
}
+45 -11
View File
@@ -2,23 +2,27 @@
namespace App\Domain\Cms;
use App\Domain\Cms\Widgets\WidgetRegistry;
use App\Domain\Cms\Sections\PageSections;
use App\Jobs\PublishPublicMedia;
use App\Models\User;
use Illuminate\Support\Facades\Schema;
use Illuminate\Validation\ValidationException;
class PageService
{
public function __construct(private readonly WidgetRegistry $widgets) {}
public function __construct(private readonly PageSections $sections) {}
/**
* Speichert einen Entwurf als neue Revision. Veröffentlicht nichts.
*
* @param array<int|string, mixed> $blocks Bausteine im Altformat oder als Widget-Hülle
* @param array<int|string, mixed> $content Abschnitte mit Slots; flache Widgets (Altformat oder Hülle)
* werden als einspaltige Abschnitte übernommen
*/
public function saveRevision(Page $page, array $blocks, ?string $seoTitle, ?string $seoDescription, ?User $author): PageRevision
public function saveRevision(Page $page, array $content, ?string $seoTitle, ?string $seoDescription, ?User $author): PageRevision
{
return $this->storeRevision($page, $this->widgets->normalize($blocks), $seoTitle, $seoDescription, $author);
$sections = $this->sections->normalize($content);
return $this->storeRevision($page, $this->sections->flatten($sections), $sections, $seoTitle, $seoDescription, $author);
}
public function publish(Page $page, PageRevision $revision): void
@@ -34,7 +38,7 @@ public function publish(Page $page, PageRevision $revision): void
}
/**
* Legt den Stand einer früheren Revision unverändert als neue Revision an. Die gespeicherten Bausteine
* Legt den Stand einer früheren Revision unverändert als neue Revision an. Abschnitte und Bausteine
* werden nicht umgeschrieben; ältere Formate werden erst beim Lesen angehoben.
*/
public function restore(Page $page, PageRevision $source, ?User $author): PageRevision
@@ -48,12 +52,33 @@ public function restore(Page $page, PageRevision $source, ?User $author): PageRe
return $this->storeRevision(
$page,
$source->blocks ?? [],
$source->sections,
$source->seo_title,
$source->seo_description,
$author,
);
}
/**
* Legt eine neue, unveröffentlichte Seite mit dem zuletzt gespeicherten Stand einer vorhandenen Seite an.
* Die Vorlage bleibt unverändert; spätere Änderungen wirken nicht auf die Kopie.
*/
public function duplicate(Page $source, string $path, ?User $author): Page
{
$revision = $source->latestRevision ?? $source->publishedRevision;
$page = Page::query()->create(['path' => $this->availablePath($path)]);
$this->saveRevision(
$page,
$revision?->sections() ?? [],
$revision?->seo_title,
$revision?->seo_description,
$author,
);
return $page;
}
/**
* Normalisiert den Pfad und prüft, dass keine andere Seite ihn verwendet.
*/
@@ -95,18 +120,27 @@ public function normalizePath(string $path): string
}
/**
* @param array<int|string, mixed> $blocks
* @param array<int|string, mixed> $blocks flache Widget-Liste (Rollback-Fassung)
* @param array<int|string, mixed>|null $sections Abschnitte; null bei Revisionen aus der Zeit vor dem Raster
*/
private function storeRevision(Page $page, array $blocks, ?string $seoTitle, ?string $seoDescription, ?User $author): PageRevision
private function storeRevision(Page $page, array $blocks, ?array $sections, ?string $seoTitle, ?string $seoDescription, ?User $author): PageRevision
{
$revision = $page->revisions()->create([
$attributes = [
'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) {
// Die Erstbefüllung der Website läuft innerhalb einer frühen Migration, bevor die Spalte existiert.
// Solche Revisionen haben keine Abschnitte und werden beim Lesen als einspaltige Abschnitte gelesen.
if ($sections !== null && Schema::hasColumn('page_revisions', 'sections')) {
$attributes['sections'] = array_values($sections);
}
$revision = $page->revisions()->create($attributes);
foreach ($this->sections->mediaPaths($revision->sections()) as $path) {
PublishPublicMedia::dispatch($path);
}
+345
View File
@@ -0,0 +1,345 @@
<?php
namespace App\Domain\Cms\Sections;
use App\Domain\Cms\Widgets\Support\PublicMedia;
use App\Domain\Cms\Widgets\WidgetRegistry;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
/**
* Abschnitts- und Slotmodell einer Seite: Seite → Abschnitte → Slots → Widget-Instanzen.
*
* Gespeicherte Hülle eines Abschnitts (Version 1):
* {id, v, layout, style: {background, image, focus, overlay, width, spacing, divider}, slots: [Widget-Hülle|null, …]}
*
* Jeder Slot enthält höchstens ein Widget aus dem zentralen Widget-Register. Abschnitte sind nicht verschachtelbar.
* Revisionen ohne Abschnitte (Bestand vor dieser Fassung) werden beim Lesen als einspaltige Abschnitte gelesen.
*/
class PageSections
{
public const VERSION = 1;
public const MAX_SECTIONS = 30;
public const MAX_WIDGETS = 60;
public function __construct(private readonly WidgetRegistry $widgets) {}
/**
* Lesepfad. Unbekannte Werte fallen auf Vorgaben zurück, unbekannte Widget-Arten entfallen.
*
* @param array<int|string, mixed>|null $sections gespeicherte Abschnitte (Spalte sections)
* @param array<int|string, mixed>|null $blocks flache Bausteinliste (Spalte blocks), nur ohne Abschnitte verwendet
* @return list<array{id: ?string, v: int, layout: string, style: array<string, mixed>, slots: list<array<string, mixed>|null>}>
*/
public function read(?array $sections, ?array $blocks = null): array
{
if ($sections === null) {
return $this->wrapWidgets($blocks ?? []);
}
$result = [];
foreach (array_values($sections) as $section) {
if (is_array($section)) {
$result[] = $this->upcastSection($section);
}
}
return $result;
}
/**
* Schreibpfad: prüft und bereinigt Abschnitte für eine neue Revision. Flache Widgets (ohne „slots“) werden
* als einspaltige Abschnitte übernommen. Alle Fehler der Seite werden gesammelt gemeldet; Schlüssel:
* „sections.N.layout“, „sections.N.style.image“, „sections.N.slots“, „sections.N.slots.M.data.feld“.
*
* @param array<int|string, mixed> $content
* @return list<array{id: string, v: int, layout: string, style: array<string, mixed>, slots: list<array<string, mixed>|null>}>
*/
public function normalize(array $content): array
{
$items = array_values($content);
if (count($items) > self::MAX_SECTIONS) {
throw ValidationException::withMessages([
'sections' => 'Eine Seite hat höchstens '.self::MAX_SECTIONS.' Abschnitte.',
]);
}
$errors = [];
$sections = [];
$seenSectionIds = [];
$seenWidgetIds = [];
$widgetCount = 0;
foreach ($items as $index => $item) {
if (! is_array($item)) {
$errors["sections.$index"] = ['Ein Abschnitt ist unvollständig.'];
continue;
}
if (! array_key_exists('slots', $item)) {
$item = ['id' => null, 'layout' => SectionLayouts::DEFAULT, 'style' => [], 'slots' => [$item]];
}
$sections[] = $this->normalizeSection($item, $index, $errors, $seenSectionIds, $seenWidgetIds, $widgetCount);
}
if ($widgetCount > self::MAX_WIDGETS) {
$errors['sections'] = ['Eine Seite enthält höchstens '.self::MAX_WIDGETS.' Widgets.'];
}
if ($errors !== []) {
throw ValidationException::withMessages($errors);
}
return $sections;
}
/**
* Widgets in Lesereihenfolge (Abschnitt für Abschnitt, Slot für Slot). Wird zusätzlich als flache
* Bausteinliste gespeichert, damit ein Code-Rollback auf die Fassung vor den Abschnitten die Inhalte
* weiterhin untereinander darstellt.
*
* @param list<array<string, mixed>> $sections
* @return list<array<string, mixed>>
*/
public function flatten(array $sections): array
{
$widgets = [];
foreach ($sections as $section) {
$count = SectionLayouts::slotCount($section['layout']);
foreach (array_slice($section['slots'], 0, $count) as $widget) {
if (is_array($widget)) {
$widgets[] = $widget;
}
}
}
return $widgets;
}
/**
* Öffentliche Medien der Seite: Widget-Bilder und Hintergrundbilder der Abschnitte.
*
* @param list<array<string, mixed>> $sections
* @return list<string>
*/
public function mediaPaths(array $sections): array
{
$paths = [];
foreach ($sections as $section) {
$style = SectionStyle::fromStored($section['style'] ?? []);
if ($style['image'] !== null && PublicMedia::isPublicPath($style['image'])) {
$paths[] = $style['image'];
}
}
foreach ($this->widgets->mediaPaths($this->flatten($sections)) as $path) {
$paths[] = $path;
}
return array_values(array_unique($paths));
}
/**
* @param list<array<string, mixed>> $sections
*/
public function pageTitle(array $sections): ?string
{
return $this->widgets->pageTitle($this->flatten($sections));
}
/**
* @param array<int|string, mixed> $blocks
* @return list<array{id: ?string, v: int, layout: string, style: array<string, mixed>, slots: list<array<string, mixed>|null>}>
*/
private function wrapWidgets(array $blocks): array
{
$sections = [];
foreach ($this->widgets->read($blocks) as $widget) {
$sections[] = [
'id' => null,
'v' => self::VERSION,
'layout' => SectionLayouts::DEFAULT,
// Bestand vor dem Raster stand in einem durchgehenden Blatt: kompakte Abstände kommen dem am nächsten.
'style' => ['spacing' => 'compact'] + SectionStyle::DEFAULTS,
'slots' => [$widget],
];
}
return $sections;
}
/**
* @param array<string, mixed> $section
* @return array{id: ?string, v: int, layout: string, style: array<string, mixed>, slots: list<array<string, mixed>|null>}
*/
private function upcastSection(array $section): array
{
$layout = SectionLayouts::has($section['layout'] ?? null) ? $section['layout'] : SectionLayouts::DEFAULT;
$slots = [];
foreach (array_values(is_array($section['slots'] ?? null) ? $section['slots'] : []) as $slot) {
$slots[] = is_array($slot) ? $this->widgets->upcast($slot) : null;
}
while (count($slots) < SectionLayouts::slotCount($layout)) {
$slots[] = null;
}
return [
'id' => is_string($section['id'] ?? null) ? $section['id'] : null,
'v' => self::VERSION,
'layout' => $layout,
'style' => SectionStyle::fromStored($section['style'] ?? []),
'slots' => $slots,
];
}
/**
* @param array<string, mixed> $section
* @param array<string, list<string>> $errors
* @param array<string, true> $seenSectionIds
* @param array<string, true> $seenWidgetIds
* @return array{id: string, v: int, layout: string, style: array<string, mixed>, slots: list<array<string, mixed>|null>}
*/
private function normalizeSection(array $section, int $index, array &$errors, array &$seenSectionIds, array &$seenWidgetIds, int &$widgetCount): array
{
$prefix = "sections.$index";
$layout = $section['layout'] ?? SectionLayouts::DEFAULT;
if (! SectionLayouts::has($layout)) {
$errors["$prefix.layout"] = ['Dieses Abschnittsraster ist nicht freigegeben.'];
$layout = SectionLayouts::DEFAULT;
}
$style = $this->normalizeStyle(is_array($section['style'] ?? null) ? $section['style'] : [], $prefix, $errors);
$units = SectionLayouts::units($layout);
$rawSlots = array_values(is_array($section['slots'] ?? null) ? $section['slots'] : []);
$filled = count(array_filter($rawSlots, fn ($slot): bool => is_array($slot)));
if ($filled > count($units)) {
$errors["$prefix.slots"] = [sprintf(
'Das Raster „%s“ hat %d %s, der Abschnitt enthält aber %d Widgets. Entfernen Sie ein Widget oder wählen Sie ein Raster mit mehr Plätzen.',
SectionLayouts::short($layout),
count($units),
count($units) === 1 ? 'Platz' : 'Plätze',
$filled,
)];
} elseif (count($rawSlots) > count($units)) {
// Überzählige Plätze sind leer: Widgets rücken in Reihenfolge nach vorn, leere Plätze entfallen.
$rawSlots = array_values(array_filter($rawSlots, fn ($slot): bool => is_array($slot)));
}
$slots = [];
foreach ($units as $position => $slotUnits) {
$block = $rawSlots[$position] ?? null;
if (! is_array($block)) {
$slots[] = null;
continue;
}
$widgetCount++;
try {
$widget = $this->widgets->normalizeWidget($block, "$prefix.slots.$position", $seenWidgetIds);
} catch (ValidationException $exception) {
foreach ($exception->errors() as $key => $messages) {
$errors[$key] = $messages;
}
$slots[] = null;
continue;
}
$type = $this->widgets->get($widget['type']);
if ($slotUnits < $type->minUnits()) {
$errors["$prefix.slots.$position.units"] = [sprintf(
'„%s“ braucht mindestens %d Rastereinheiten; dieser Platz hat %d. Wählen Sie ein breiteres Raster oder einen breiteren Platz.',
$type->label(),
$type->minUnits(),
$slotUnits,
)];
}
$slots[] = $widget;
}
$id = $section['id'] ?? null;
if (! is_string($id) || preg_match('/^[A-Za-z0-9-]{1,64}$/', $id) !== 1 || isset($seenSectionIds[$id])) {
$id = (string) Str::uuid();
}
$seenSectionIds[$id] = true;
return [
'id' => $id,
'v' => self::VERSION,
'layout' => $layout,
'style' => $style,
'slots' => $slots,
];
}
/**
* @param array<string, mixed> $style
* @param array<string, list<string>> $errors
* @return array<string, mixed>
*/
private function normalizeStyle(array $style, string $prefix, array &$errors): array
{
$result = SectionStyle::DEFAULTS;
$enums = SectionStyle::enums();
foreach ($style as $key => $value) {
if ($key === 'image' || str_starts_with((string) $key, '_')) {
continue;
}
if (! isset($enums[$key])) {
$errors["$prefix.style.$key"] = ['Diese Gestaltungsoption ist nicht freigegeben.'];
continue;
}
if ($value === null || $value === '') {
continue;
}
if (! is_string($value) || ! array_key_exists($value, $enums[$key])) {
$errors["$prefix.style.$key"] = ['Dieser Gestaltungswert ist nicht freigegeben.'];
continue;
}
$result[$key] = $value;
}
$upload = PublicMedia::fromUploadState($style['_upload'] ?? null);
$image = $upload ?? PublicMedia::fromUploadState($style['image'] ?? null);
if ($result['background'] === 'image') {
if ($image === null) {
$errors["$prefix.style.image"] = ['Bitte ein Hintergrundbild wählen oder hochladen.'];
} elseif (! PublicMedia::isPublicPath($image)) {
$errors["$prefix.style.image"] = ['Das Hintergrundbild liegt nicht im öffentlichen Medienbereich.'];
}
$result['image'] = $image;
} else {
$result['image'] = null;
}
return $result;
}
}
+130
View File
@@ -0,0 +1,130 @@
<?php
namespace App\Domain\Cms\Sections;
/**
* Freigegebene Abschnittsraster. Ein Raster teilt die Abschnittsbreite in höchstens vier logische Einheiten.
* Die Kennungen sind gespeichert und ändern sich nie; neue Raster werden ergänzt, nicht umbenannt.
*
* Die Einheiten werden nicht als eigenes CSS-Grundraster umgesetzt, sondern als Spaltenverhältnis (fr)
* des Abschnittsrasters. Leere Slots entfallen auf der veröffentlichten Seite; die übrigen Slots teilen
* sich die Breite im Verhältnis ihrer Einheiten.
*/
final class SectionLayouts
{
public const DEFAULT = 'u4';
/** @var array<string, list<int>> */
public const UNITS = [
'u4' => [4],
'u2_2' => [2, 2],
'u1_3' => [1, 3],
'u3_1' => [3, 1],
'u1_2_1' => [1, 2, 1],
'u1_1_1_1' => [1, 1, 1, 1],
];
/** @var array<string, string> */
public const LABELS = [
'u4' => 'Volle Breite',
'u2_2' => 'Zwei gleich breit',
'u1_3' => 'Schmal und breit',
'u3_1' => 'Breit und schmal',
'u1_2_1' => 'Mitte betont',
'u1_1_1_1' => 'Vier gleich breit',
];
public static function has(mixed $key): bool
{
return is_string($key) && isset(self::UNITS[$key]);
}
/**
* @return list<int>
*/
public static function units(string $key): array
{
return self::UNITS[$key] ?? self::UNITS[self::DEFAULT];
}
public static function slotCount(string $key): int
{
return count(self::units($key));
}
/** Kurzform wie „1 + 3“. */
public static function short(string $key): string
{
return implode(' + ', self::units($key));
}
public static function label(string $key): string
{
return (self::LABELS[$key] ?? self::LABELS[self::DEFAULT]).' ('.self::short($key).')';
}
/**
* @return array<string, string>
*/
public static function options(): array
{
$options = [];
foreach (array_keys(self::UNITS) as $key) {
$options[$key] = self::label($key);
}
return $options;
}
/**
* Spaltenvorlagen für die Slots, die tatsächlich etwas darstellen.
*
* - Desktop (Abschnitt ab 60rem): Verhältnis der Einheiten.
* - Tablet (ab 40rem): gleich breite Slots bleiben nebeneinander (zwei oder drei Spalten, vier Slots als 2 × 2);
* ungleiche Raster stapeln, damit kein Slot unter etwa 13rem fällt.
* - Smartphone: immer eine Spalte. Die Lese- und Fokusreihenfolge bleibt die Reihenfolge der Slots.
*
* @param list<int> $units
* @return array{lg: string, md: string}
*/
public static function columns(array $units): array
{
$units = array_values(array_filter($units, fn ($unit): bool => is_int($unit) && $unit > 0));
$count = count($units);
if ($count <= 1) {
return ['lg' => 'minmax(0, 1fr)', 'md' => 'minmax(0, 1fr)'];
}
$lg = implode(' ', array_map(fn (int $unit): string => "minmax(0, {$unit}fr)", $units));
$equal = count(array_unique($units)) === 1;
$md = match (true) {
! $equal => 'minmax(0, 1fr)',
$count === 3 => 'repeat(3, minmax(0, 1fr))',
default => 'repeat(2, minmax(0, 1fr))',
};
return ['lg' => $lg, 'md' => $md];
}
/**
* Symbolbild des Rasters für die grafische Auswahl im Editor (rein dekorativ).
*/
public static function schematicSvg(string $key): string
{
$units = self::units($key);
$gap = 2;
$width = 56 - $gap * (count($units) - 1);
$x = 2;
$rects = '';
foreach ($units as $unit) {
$w = (int) round($width * $unit / 4);
$rects .= sprintf('<rect x="%d" y="4" width="%d" height="20" rx="1.5"/>', $x, $w);
$x += $w + $gap;
}
return '<svg class="luf-layout-schematic" viewBox="0 0 60 28" width="60" height="28" aria-hidden="true" focusable="false">'.$rects.'</svg>';
}
}
+127
View File
@@ -0,0 +1,127 @@
<?php
namespace App\Domain\Cms\Sections;
use App\Domain\Cms\Widgets\RenderContext;
use App\Domain\Cms\Widgets\Support\PublicMedia;
use App\Domain\Cms\Widgets\WidgetRenderer;
use Illuminate\Support\HtmlString;
/**
* Einziger Darstellungsweg für Abschnitte: öffentliche Seite und Seitenvorschau rufen denselben Renderer auf.
*
* Regeln:
* - Leere Slots erzeugen keine Leerfläche; die übrigen Slots teilen sich die Breite im Verhältnis ihrer Einheiten.
* - Ein Abschnitt ohne darstellbares Widget entfällt samt Hintergrund und Trenner.
* - Das erste dargestellte Widget der Seite ist der Seiteneinstieg (Überschrift erster Ordnung).
* - Trenner stehen zwischen Abschnitten, nie nach dem letzten.
*/
class SectionRenderer
{
public function __construct(private readonly WidgetRenderer $widgets) {}
/**
* @param list<array<string, mixed>> $sections gelesene Abschnitte (PageSections::read)
*/
public function renderAll(array $sections, RenderContext $context): HtmlString
{
$rendered = [];
$first = true;
foreach ($sections as $section) {
$cells = [];
$units = SectionLayouts::units($section['layout']);
foreach ($units as $position => $slotUnits) {
$widget = $section['slots'][$position] ?? null;
if (! is_array($widget)) {
continue;
}
$html = $this->widgets->renderWidget($widget, $context, $first);
if ($html !== '') {
$first = false;
$cells[] = ['units' => $slotUnits, 'html' => $html];
}
}
if ($cells !== []) {
$rendered[] = ['section' => $section, 'cells' => $cells];
}
}
$html = '';
$last = count($rendered) - 1;
foreach ($rendered as $index => $item) {
$html .= $this->renderSection($item['section'], $item['cells'], $index);
$divider = $item['section']['style']['divider'] ?? 'none';
if ($index < $last && in_array($divider, ['line', 'accent'], true)) {
$html .= '<div class="section-divider section-divider-'.$divider.'" aria-hidden="true"><span></span></div>';
}
}
return new HtmlString($html);
}
/**
* @param array<string, mixed> $section
* @param list<array{units: int, html: string}> $cells
*/
private function renderSection(array $section, array $cells, int $index): string
{
$style = SectionStyle::fromStored($section['style'] ?? []);
$columns = SectionLayouts::columns(array_column($cells, 'units'));
$hasImage = $style['background'] === 'image' && $style['image'] !== null && PublicMedia::isPublicPath($style['image']);
$classes = [
'page-section',
'section-bg-'.($hasImage ? 'image' : ($style['background'] === 'image' ? 'default' : $style['background'])),
'section-width-'.$style['width'],
'section-space-'.$style['spacing'],
'section-layout-'.str_replace('_', '-', $section['layout']),
];
if ($hasImage) {
$classes[] = 'section-overlay-'.$style['overlay'];
}
// Bedeutungswerte der Fläche (tokens.css): helle Schrift auf dunklen Flächen, gelber Fokus.
$scope = match (true) {
$hasImage && $style['overlay'] === 'dark' => 'scope-dark',
$hasImage => 'scope-light',
$style['background'] === 'dark' => 'scope-dark',
$style['background'] === 'accent' => 'scope-accent',
default => null,
};
if ($scope !== null) {
$classes[] = $scope;
}
if ($style['divider'] === 'space') {
$classes[] = 'section-divider-space';
}
$id = is_string($section['id'] ?? null) ? ' id="bereich-'.e($section['id']).'"' : '';
$html = '<div class="'.e(implode(' ', $classes)).'"'.$id.'>';
if ($hasImage) {
// Das Bild des ersten Abschnitts ist meist das größte sichtbare Element und wird nicht verzögert geladen.
$loading = $index === 0 ? 'loading="eager" fetchpriority="high"' : 'loading="lazy"';
$html .= '<img class="page-section-image" src="'.e(PublicMedia::url($style['image'])).'" alt="" '.$loading.' decoding="async"'
.' style="object-position: '.e(SectionStyle::FOCUS_POSITIONS[$style['focus']]).'">';
}
$html .= '<div class="page-section-inner"><div class="section-grid" data-slots="'.count($cells).'"'
.' style="--section-cols-lg: '.e($columns['lg']).'; --section-cols-md: '.e($columns['md']).'">';
foreach ($cells as $cell) {
$html .= '<div class="section-slot" data-units="'.$cell['units'].'">'.$cell['html'].'</div>';
}
return $html.'</div></div></div>';
}
}
+150
View File
@@ -0,0 +1,150 @@
<?php
namespace App\Domain\Cms\Sections;
/**
* Semantische Abschnittsgestaltung. Jeder Wert ist eine Aufzählung, die auf zentrale Design-Tokens
* abgebildet wird (resources/css/app.css, Abschnitt „Abschnitte“). Keine freie CSS- oder Farbangabe.
*/
final class SectionStyle
{
/** @var array<string, string> */
public const BACKGROUNDS = [
'default' => 'Standard (ohne eigene Fläche)',
'light' => 'Helle Markenfläche',
'dark' => 'Dunkle Markenfläche',
'accent' => 'Markenakzent',
'image' => 'Hintergrundbild',
];
/** @var array<string, string> */
public const WIDTHS = [
'narrow' => 'Schmal (Lesebreite)',
'standard' => 'Standard',
'wide' => 'Breit',
'full' => 'Volle Breite',
];
/** @var array<string, string> */
public const SPACINGS = [
'compact' => 'Kompakt',
'normal' => 'Normal',
'large' => 'Großzügig',
];
/** @var array<string, string> */
public const DIVIDERS = [
'none' => 'Kein Trenner',
'space' => 'Zusätzlicher Abstand',
'line' => 'Dezente Linie',
'accent' => 'Markenakzent',
];
/** @var array<string, string> */
public const OVERLAYS = [
'light' => 'Helle Überlagerung (dunkle Schrift)',
'dark' => 'Dunkle Überlagerung (helle Schrift)',
'none' => 'Keine Überlagerung',
];
/** @var array<string, string> */
public const FOCUS = [
'center' => 'Mitte',
'top' => 'Oben',
'bottom' => 'Unten',
'left' => 'Links',
'right' => 'Rechts',
'top_left' => 'Oben links',
'top_right' => 'Oben rechts',
'bottom_left' => 'Unten links',
'bottom_right' => 'Unten rechts',
];
/** Fokuspunkt als Objektposition des Bildes; bestimmt den Zuschnitt auf schmalen Bildschirmen. */
public const FOCUS_POSITIONS = [
'center' => '50% 50%',
'top' => '50% 0%',
'bottom' => '50% 100%',
'left' => '0% 50%',
'right' => '100% 50%',
'top_left' => '0% 0%',
'top_right' => '100% 0%',
'bottom_left' => '0% 100%',
'bottom_right' => '100% 100%',
];
public const DEFAULTS = [
'background' => 'default',
'image' => null,
'focus' => 'center',
'overlay' => 'light',
'width' => 'standard',
'spacing' => 'normal',
'divider' => 'none',
];
/**
* Aufzählungsfelder und ihre zulässigen Werte.
*
* @return array<string, array<string, string>>
*/
public static function enums(): array
{
return [
'background' => self::BACKGROUNDS,
'focus' => self::FOCUS,
'overlay' => self::OVERLAYS,
'width' => self::WIDTHS,
'spacing' => self::SPACINGS,
'divider' => self::DIVIDERS,
];
}
/**
* Lesepfad: gespeicherte Werte; Unbekanntes fällt auf die Vorgabe zurück, damit alte oder fremde Daten
* nie eine Seite brechen.
*
* @return array{background: string, image: ?string, focus: string, overlay: string, width: string, spacing: string, divider: string}
*/
public static function fromStored(mixed $style): array
{
$style = is_array($style) ? $style : [];
$result = self::DEFAULTS;
foreach (self::enums() as $key => $options) {
$value = $style[$key] ?? null;
if (is_string($value) && array_key_exists($value, $options)) {
$result[$key] = $value;
}
}
$result['image'] = $result['background'] === 'image' && is_string($style['image'] ?? null) ? $style['image'] : null;
return $result;
}
/**
* Kurzbeschreibung für die Abschnittsliste im Editor.
*
* @param array<string, mixed> $style
*/
public static function summary(array $style): string
{
$style = self::fromStored($style);
$parts = [self::BACKGROUNDS[$style['background']]];
if ($style['width'] !== 'standard') {
$parts[] = self::WIDTHS[$style['width']];
}
if ($style['spacing'] !== 'normal') {
$parts[] = 'Abstand '.mb_strtolower(self::SPACINGS[$style['spacing']]);
}
if ($style['divider'] !== 'none') {
$parts[] = 'Trenner: '.self::DIVIDERS[$style['divider']];
}
return implode(' · ', $parts);
}
}
+104
View File
@@ -0,0 +1,104 @@
<?php
namespace App\Domain\Cms;
use Illuminate\Support\Collection;
/**
* Baut Kopf- und Fußnavigation aus dem CMS-Navigationsmodell. Keine fest codierten Menüpunkte.
*
* Die Ausgabe hängt nur von der Navigation und dem angefragten Pfad ab, nie vom Anmeldestatus,
* damit öffentliche Seiten für alle Besucher gleich ausgeliefert werden können (ADR-32).
*/
final class SiteNavigation
{
/**
* @param Collection<int, NavigationItem> $items sichtbare Einträge, sortiert
*/
public function __construct(private readonly Collection $items, private readonly string $currentPath) {}
/**
* @param Collection<int, NavigationItem> $items
*/
public static function forPath(Collection $items, string $path): self
{
return new self($items, '/'.trim($path, '/'));
}
/**
* Hauptnavigation mit einer Ebene Untermenü. Untereinträge eines ausgeblendeten Eintrags sind ebenfalls verborgen.
*
* @return list<array{id: int, label: string, href: ?string, current: bool, activeTrail: bool, children: list<array{id: int, label: string, href: string, current: bool}>}>
*/
public function header(): array
{
$topLevel = $this->items->where('placement', 'header')->whereNull('parent_id');
$entries = [];
foreach ($topLevel as $item) {
$children = [];
foreach ($this->items->where('parent_id', $item->id) as $child) {
$href = $child->href();
if ($href !== null) {
$children[] = [
'id' => $child->id,
'label' => $child->label,
'href' => $href,
'current' => $this->isCurrent($child),
];
}
}
$href = $item->href();
if ($href === null && $children === []) {
continue;
}
$current = $href !== null && $this->isCurrent($item);
$entries[] = [
'id' => $item->id,
'label' => $item->label,
'href' => $href,
'current' => $current,
'activeTrail' => $current || in_array(true, array_column($children, 'current'), true),
'children' => $children,
];
}
return $entries;
}
/**
* Spalten des Fußbereichs in fester Reihenfolge; Gruppen ohne Einträge entfallen.
*
* @return list<array{key: string, heading: string, links: list<array{label: string, href: string, current: bool}>}>
*/
public function footerGroups(): array
{
$groups = [];
foreach (NavigationItem::FOOTER_GROUPS as $placement => $heading) {
$links = [];
foreach ($this->items->where('placement', $placement) as $item) {
$href = $item->href();
if ($href !== null) {
$links[] = ['label' => $item->label, 'href' => $href, 'current' => $this->isCurrent($item)];
}
}
if ($links !== []) {
$groups[] = ['key' => $placement, 'heading' => $heading, 'links' => $links];
}
}
return $groups;
}
private function isCurrent(NavigationItem $item): bool
{
return $item->targetPath() === $this->currentPath;
}
}
@@ -25,6 +25,23 @@ public function description(): string
return 'Hervorgehobene Fläche mit Überschrift, Text und einer Schaltfläche.';
}
public function minUnits(): int
{
return 1;
}
public function preferredUnits(): int
{
return 2;
}
public function stages(): array
{
return [
'fluid' => 'Text und Schaltfläche untereinander, Schaltfläche volle Breite unter 20rem',
];
}
public function icon(): string
{
return 'heroicon-o-megaphone';
@@ -35,6 +35,24 @@ public function description(): string
return 'Mehrere Karten mit Titel, Text, Linkziel und optionalem Bild. Als Raster oder kompakte Liste.';
}
public function minUnits(): int
{
return 1;
}
public function preferredUnits(): int
{
return 4;
}
public function stages(): array
{
return [
'narrow' => 'eine Karte je Zeile',
'wide' => 'so viele Karten nebeneinander, wie bei mindestens 14rem Kartenbreite passen',
];
}
public function icon(): string
{
return 'heroicon-o-squares-2x2';
@@ -37,6 +37,24 @@ public function description(): string
return 'Ausgewählte Programme und Module; Titel und Beschreibung kommen automatisch aus den Fachdaten.';
}
public function minUnits(): int
{
return 1;
}
public function preferredUnits(): int
{
return 4;
}
public function stages(): array
{
return [
'narrow' => 'eine Karte je Zeile, Symbolfläche über dem Text',
'wide' => 'mehrere Karten nebeneinander ab 16rem Kartenbreite',
];
}
public function icon(): string
{
return 'heroicon-o-rectangle-stack';
@@ -24,6 +24,23 @@ public function description(): string
return 'Häufige Fragen mit Antworten.';
}
public function minUnits(): int
{
return 2;
}
public function preferredUnits(): int
{
return 4;
}
public function stages(): array
{
return [
'fluid' => 'Fragen untereinander; Antwortlänge auf Lesebreite begrenzt',
];
}
public function icon(): string
{
return 'heroicon-o-question-mark-circle';
@@ -23,6 +23,23 @@ public function description(): string
return 'Abschnittsüberschrift mit kurzem Einleitungstext.';
}
public function minUnits(): int
{
return 1;
}
public function preferredUnits(): int
{
return 4;
}
public function stages(): array
{
return [
'fluid' => 'Überschriftgröße folgt der Slotbreite',
];
}
public function icon(): string
{
return 'heroicon-o-h1';
@@ -30,6 +30,24 @@ public function description(): string
return 'Großer Seiteneinstieg mit Überschrift, Beschreibung, optionalem Bild und optionaler Schaltfläche.';
}
public function minUnits(): int
{
return 2;
}
public function preferredUnits(): int
{
return 4;
}
public function stages(): array
{
return [
'narrow' => 'unter 48rem Slotbreite: Bild unter dem Text',
'wide' => 'ab 48rem: Bild neben dem Text, größere Überschrift',
];
}
public function icon(): string
{
return 'heroicon-o-sparkles';
@@ -35,6 +35,24 @@ public function description(): string
return 'Bild neben formatiertem Text; Bild links oder rechts, auf dem Smartphone untereinander.';
}
public function minUnits(): int
{
return 2;
}
public function preferredUnits(): int
{
return 4;
}
public function stages(): array
{
return [
'narrow' => 'unter 36rem Slotbreite: Bild über dem Text',
'wide' => 'ab 36rem: Bild links oder rechts neben dem Text',
];
}
public function version(): int
{
return 2;
@@ -23,6 +23,23 @@ public function description(): string
return 'Längerer Text in Absätzen. Eine Leerzeile beginnt einen neuen Absatz.';
}
public function minUnits(): int
{
return 1;
}
public function preferredUnits(): int
{
return 2;
}
public function stages(): array
{
return [
'fluid' => 'Zeilenlänge höchstens etwa 70 Zeichen',
];
}
public function icon(): string
{
return 'heroicon-o-bars-3-bottom-left';
+49 -34
View File
@@ -45,6 +45,10 @@ public function register(WidgetType $type): void
throw new InvalidArgumentException("Widget „{$key}“ braucht eine Schemaversion ab 1.");
}
if ($type->minUnits() < 1 || $type->minUnits() > 4 || $type->preferredUnits() < $type->minUnits() || $type->preferredUnits() > 4) {
throw new InvalidArgumentException("Widget „{$key}“ braucht eine Mindest- und Vorzugsbreite zwischen 1 und 4 Rastereinheiten.");
}
if ($type->variants() === []) {
throw new InvalidArgumentException("Widget „{$key}“ braucht mindestens eine Darstellungsvariante.");
}
@@ -137,7 +141,7 @@ public function upcast(array $block): ?array
}
/**
* Prüft und bereinigt Bausteine für eine neue Revision.
* Prüft und bereinigt eine flache Bausteinliste (Fehlerschlüssel "blocks.N…").
*
* @param array<int|string, mixed> $blocks
* @return list<array{id: string, type: string, v: int, variant: string, settings: array<string, mixed>, data: array<string, mixed>, refs: array<string, mixed>}>
@@ -148,42 +152,53 @@ public function normalize(array $blocks): array
$seenIds = [];
foreach (array_values($blocks) as $index => $block) {
if (! is_array($block)) {
throw ValidationException::withMessages([
"blocks.$index" => 'Ein Baustein ist unvollständig.',
]);
}
if (! $this->has($block['type'] ?? null)) {
throw ValidationException::withMessages([
"blocks.$index.type" => 'Dieser Bausteintyp ist nicht freigegeben.',
]);
}
$type = $this->get($block['type']);
if (array_key_exists('v', $block) && (int) $block['v'] > $type->version()) {
throw ValidationException::withMessages([
"blocks.$index.v" => 'Dieser Baustein stammt aus einer neueren Programmfassung und kann hier nicht gespeichert werden.',
]);
}
$requested = $block['variant'] ?? null;
$isCurrent = array_key_exists('v', $block) && (int) $block['v'] === $type->version();
if ($isCurrent && is_string($requested) && $requested !== '' && ! array_key_exists($requested, $type->variants())) {
throw ValidationException::withMessages([
"blocks.$index.variant" => 'Diese Darstellungsvariante ist für den Baustein nicht freigegeben.',
]);
}
$widget = $this->upcast($block);
$normalized[] = $this->validateOne($type, $widget, $index, $seenIds);
$normalized[] = $this->normalizeWidget($block, "blocks.$index", $seenIds);
}
return $normalized;
}
/**
* Prüft und bereinigt einen einzelnen Baustein für eine neue Revision. Der Aufrufer führt die Menge
* bereits vergebener Kennungen über die ganze Seite, damit kopierte Widgets neue Kennungen erhalten.
*
* @param array<string, true> $seenIds
* @return array{id: string, type: string, v: int, variant: string, settings: array<string, mixed>, data: array<string, mixed>, refs: array<string, mixed>}
*/
public function normalizeWidget(mixed $block, string $errorPrefix, array &$seenIds): array
{
if (! is_array($block)) {
throw ValidationException::withMessages([
$errorPrefix => 'Ein Baustein ist unvollständig.',
]);
}
if (! $this->has($block['type'] ?? null)) {
throw ValidationException::withMessages([
"$errorPrefix.type" => 'Dieser Bausteintyp ist nicht freigegeben.',
]);
}
$type = $this->get($block['type']);
if (array_key_exists('v', $block) && (int) $block['v'] > $type->version()) {
throw ValidationException::withMessages([
"$errorPrefix.v" => 'Dieser Baustein stammt aus einer neueren Programmfassung und kann hier nicht gespeichert werden.',
]);
}
$requested = $block['variant'] ?? null;
$isCurrent = array_key_exists('v', $block) && (int) $block['v'] === $type->version();
if ($isCurrent && is_string($requested) && $requested !== '' && ! array_key_exists($requested, $type->variants())) {
throw ValidationException::withMessages([
"$errorPrefix.variant" => 'Diese Darstellungsvariante ist für den Baustein nicht freigegeben.',
]);
}
return $this->validateOne($type, $this->upcast($block), $errorPrefix, $seenIds);
}
/**
* Gespeicherte Bausteine einer Revision als aktuelle Hüllen; unbekannte Arten entfallen.
*
@@ -241,7 +256,7 @@ public function mediaPaths(?array $blocks): array
* @param array<string, true> $seenIds
* @return array{id: string, type: string, v: int, variant: string, settings: array<string, mixed>, data: array<string, mixed>, refs: array<string, mixed>}
*/
private function validateOne(WidgetType $type, array $widget, int $index, array &$seenIds): array
private function validateOne(WidgetType $type, array $widget, string $errorPrefix, array &$seenIds): array
{
$errors = new WidgetErrors;
@@ -292,7 +307,7 @@ private function validateOne(WidgetType $type, array $widget, int $index, array
if (! $errors->isEmpty()) {
$messages = [];
foreach ($errors->all() as $key => $list) {
$messages["blocks.$index.$key"] = $list;
$messages["$errorPrefix.$key"] = $list;
}
throw ValidationException::withMessages($messages);
+26
View File
@@ -34,6 +34,32 @@ public function version(): int
return 1;
}
/**
* Kleinste Slotbreite in logischen Rastereinheiten (1 bis 4), in der das Widget auf dem Desktop lesbar bleibt.
* Ein schmalerer Slot wird beim Speichern abgewiesen. Auf Tablet und Smartphone stapeln die Slots ohnehin.
*/
public function minUnits(): int
{
return 1;
}
/** Empfohlene Slotbreite in Rastereinheiten; Hinweis in der Widget-Auswahl. */
public function preferredUnits(): int
{
return 4;
}
/**
* Darstellungsstufen nach verfügbarer Breite (Container-Abfragen in der Widget-Ansicht): Kennung => Beschreibung.
* Dokumentiert, wie sich das Widget an schmale und breite Slots anpasst.
*
* @return array<string, string>
*/
public function stages(): array
{
return ['fluid' => 'passt sich fließend an jede Slotbreite an'];
}
/** Heroicon-Name für Auswahl und Liste im Editor. */
public function icon(): string
{