- 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>
128 lines
5.0 KiB
PHP
128 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Cms\Sections;
|
|
|
|
use App\Domain\Cms\Widgets\RenderContext;
|
|
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
|
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, $context);
|
|
|
|
$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, RenderContext $context): string
|
|
{
|
|
$style = SectionStyle::fromStored($section['style'] ?? []);
|
|
$columns = SectionLayouts::columns(array_column($cells, 'units'));
|
|
// Hintergrundbild aus dem Medienmanager: öffentlich nur mit Website-Freigabe (WebsiteImage → WebsiteMedia).
|
|
$imageUrl = $style['background'] === 'image' ? app(WebsiteImage::class)->url($style['image'], $context->preview) : null;
|
|
$hasImage = $imageUrl !== null;
|
|
|
|
$classes = [
|
|
'page-section',
|
|
'section-bg-'.($hasImage ? 'image' : ($style['background'] === 'image' ? 'default' : $style['background'])),
|
|
'section-width-'.$style['width'],
|
|
'section-space-top-'.$style['spacing_top'],
|
|
'section-space-bottom-'.$style['spacing_bottom'],
|
|
'section-gap-'.$style['gap'],
|
|
'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;
|
|
}
|
|
|
|
$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($imageUrl).'" 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>';
|
|
}
|
|
}
|