- Einstieg, Bild und Text, redaktionelle Karten, Premium-Karten und Abschnittshintergrund speichern die Kennung des Mediums (Bildschlüssel image) und lesen über WebsiteMedia; öffentlich nur mit Website-Freigabe, in der Redaktionsvorschau sonst das Vorschaubild mit Hinweis. - Gemeinsame Felder: Medienpicker mit Vorschaubild und Status, Upload direkt über WebsiteIntake, Anzeige des gewählten Mediums mit Verweis auf den Medienmanager. Die CMS-eigene Bildauswahl entfällt. - Frühere CMS-Bilder übernimmt ein Warteschlangen-Job (dedupliziert, nichts gelöscht); website_media_aliases ordnet frühere Pfade zu, wirksam erst nach der ersten Website-Freigabe; /medien/cms/ folgt danach der Freigabe. - Medienansicht nennt die Website-Seiten, die ein Bild verwenden. - Bewusst geändert: Der Alternativtext gehört zum Medium und ist im Widget nur noch eine optionale Abweichung; die Tests zur Alt-Text-Pflicht prüfen jetzt Übernahme und andere Registry-Fehler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
245 lines
9.4 KiB
PHP
245 lines
9.4 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Cms\Sections;
|
|
|
|
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
|
|
|
/**
|
|
* 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' => 'Lesebereich',
|
|
'standard' => 'Standard',
|
|
'wide' => 'Breit',
|
|
'full' => 'Vollbreite',
|
|
];
|
|
|
|
/**
|
|
* Gemeinsame Stufen der drei Abstände eines Abschnitts (Hülle Version 2):
|
|
* - spacing_top: Abstand vor dem Inhalt (oben),
|
|
* - spacing_bottom: Abstand nach dem Inhalt (unten),
|
|
* - gap: Abstand zwischen den Plätzen im Abschnittsraster, nebeneinander und gestapelt.
|
|
* Zwischen zwei Abschnitten addieren sich „unten“ des ersten und „oben“ des zweiten; es gibt keine weitere
|
|
* versteckte Vorgabe. Liegt eine eigene Fläche (Hintergrund) vor, liegen oben und unten innerhalb dieser Fläche.
|
|
* Werte: resources/css/tokens.css (--section-space-*, --section-gap-*).
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
public const SPACINGS = [
|
|
'none' => 'Kein Abstand',
|
|
'compact' => 'Kompakt',
|
|
'normal' => 'Normal',
|
|
'large' => 'Großzügig',
|
|
];
|
|
|
|
/** @var array<string, string> */
|
|
public const DIVIDERS = [
|
|
'none' => 'Kein Trenner',
|
|
'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_top' => 'compact',
|
|
'spacing_bottom' => 'compact',
|
|
'gap' => '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_top' => self::SPACINGS,
|
|
'spacing_bottom' => self::SPACINGS,
|
|
'gap' => 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_top: string, spacing_bottom: string, gap: 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' ? WebsiteImage::normalize($style['image'] ?? null) : 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_top'] !== self::DEFAULTS['spacing_top'] || $style['spacing_bottom'] !== self::DEFAULTS['spacing_bottom']) {
|
|
$parts[] = 'Abstand oben '.mb_strtolower(self::SPACINGS[$style['spacing_top']])
|
|
.', unten '.mb_strtolower(self::SPACINGS[$style['spacing_bottom']]);
|
|
}
|
|
|
|
if ($style['gap'] !== 'normal') {
|
|
$parts[] = 'Widget-Abstand '.mb_strtolower(self::SPACINGS[$style['gap']]);
|
|
}
|
|
|
|
if ($style['divider'] !== 'none') {
|
|
$parts[] = 'Trenner: '.self::DIVIDERS[$style['divider']];
|
|
}
|
|
|
|
return implode(' · ', $parts);
|
|
}
|
|
|
|
/**
|
|
* Ob eine gespeicherte Gestaltung noch die Abstände der Hülle Version 1 trägt
|
|
* („Abstand oben und unten“ spacing, Abweichung „Abstand oben“ same/small/none).
|
|
*
|
|
* @param array<string, mixed> $style
|
|
*/
|
|
public static function hasLegacySpacing(array $style): bool
|
|
{
|
|
return array_key_exists('spacing', $style)
|
|
|| in_array($style['spacing_top'] ?? null, ['same', 'small'], true);
|
|
}
|
|
|
|
/**
|
|
* Übersetzt die Abstände der Hülle Version 1 in die drei Werte der Version 2, ohne die Darstellung zu ändern.
|
|
*
|
|
* Version 1 rechnete so: jeder Abschnitt oben und unten „spacing“ (Vorgabe normal); die Abweichung
|
|
* „Abstand oben“ ersetzte nur oben (small/none); und eine versteckte Regel setzte oben auf null, wenn ein Abschnitt
|
|
* ohne eigene Fläche direkt auf einen Abschnitt ohne eigene Fläche folgte (ohne Linien- oder Akzenttrenner dazwischen).
|
|
* Diese Regel wird hier als „oben: kein Abstand“ ausgeschrieben. „Gering“ hat keine eigene Stufe mehr und wird
|
|
* „Kompakt“ (dokumentierte Abweichung). Der Widget-Abstand entspricht dem bisherigen festen Rasterabstand („normal“).
|
|
*
|
|
* @param list<array<string, mixed>> $sections Abschnitte in Lesereihenfolge (mit style und slots)
|
|
* @param bool $byVersion true: jede Hülle mit v < 2 gilt als Version 1 (Lesepfad gespeicherter Revisionen);
|
|
* false: nur Gestaltungen mit alten Schlüsseln (Eingaben ohne Versionsangabe)
|
|
* @return list<array<string, mixed>> dieselben Abschnitte mit übersetzter Gestaltung
|
|
*/
|
|
public static function migrateSpacing(array $sections, bool $byVersion = false): array
|
|
{
|
|
$previous = null;
|
|
|
|
foreach ($sections as $index => $section) {
|
|
$style = is_array($section['style'] ?? null) ? $section['style'] : [];
|
|
$rendered = is_array($section['slots'] ?? null) && array_filter($section['slots'], 'is_array') !== [];
|
|
|
|
$background = is_string($style['background'] ?? null) && isset(self::BACKGROUNDS[$style['background']]) ? $style['background'] : 'default';
|
|
if ($background === 'image' && WebsiteImage::normalize($style['image'] ?? null) === null) {
|
|
$background = 'default';
|
|
}
|
|
$divider = in_array($style['divider'] ?? null, ['line', 'accent'], true) ? $style['divider'] : 'none';
|
|
|
|
$legacy = $byVersion ? (int) ($section['v'] ?? 1) < 2 : self::hasLegacySpacing($style);
|
|
|
|
if ($legacy) {
|
|
$level = in_array($style['spacing'] ?? null, ['compact', 'normal', 'large'], true) ? $style['spacing'] : 'normal';
|
|
$override = $style['spacing_top'] ?? 'same';
|
|
$collapsed = $background === 'default' && $previous !== null && $previous['background'] === 'default' && ! in_array($previous['divider'], ['line', 'accent'], true);
|
|
|
|
$style['spacing_top'] = match (true) {
|
|
$override === 'none' => 'none',
|
|
$override === 'small' => 'compact',
|
|
$collapsed => 'none',
|
|
default => $level,
|
|
};
|
|
$style['spacing_bottom'] = $level;
|
|
$style['gap'] = 'normal';
|
|
|
|
// Trenner „Zusätzlicher Abstand“ (Version 1) fügte unten noch einmal den Abschnittsabstand an.
|
|
if (($style['divider'] ?? null) === 'space') {
|
|
$style['spacing_bottom'] = ['compact' => 'normal', 'normal' => 'large', 'large' => 'large'][$level];
|
|
$style['divider'] = 'none';
|
|
}
|
|
unset($style['spacing']);
|
|
$sections[$index]['style'] = $style;
|
|
}
|
|
|
|
if ($rendered) {
|
|
$previous = ['background' => $background, 'divider' => $divider];
|
|
}
|
|
}
|
|
|
|
return $sections;
|
|
}
|
|
}
|