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

+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);
}
}