- Seitenliste: zuletzt bearbeitete Seiten zuerst, „Zuletzt bearbeitet“ in deutscher Zeit (jede Revision und Veröffentlichung aktualisiert die Seite), Pfad und Datum sortierbar, 25/50/100 je Seite. Bisher stand eine neue Seite ohne Suche auf einer späteren Listenseite. - Kopfzeile und Fußbereich zeigen die freigegebene Lara-&-Felix- Wortmarke (Kompaktfassung aus Brand-UI-Kit 08) als zugeschnittene WebP-Ableitung mit festen Maßen; Ausgangszustand ≈ 80 px, kompakt 60 px, Smartphone 48 px. Mitgliederbereich unverändert. - Abschnittsgestaltung „Abstand oben“ (wie Abstand / gering / kein): Der erste Abschnitt kann direkt unter der Kopfzeile beginnen; der Abstand unten und alle anderen Abschnitte bleiben unverändert. Tests: Erwartung an die Wortmarke bewusst angepasst (brand-logo statt brand-lockup); neue Tests für Liste, Bearbeitungsdatum und Abstand oben. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
129 lines
4.9 KiB
PHP
129 lines
4.9 KiB
PHP
<?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'],
|
|
...($style['spacing_top'] !== 'same' ? ['section-space-top-'.$style['spacing_top']] : []),
|
|
'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>';
|
|
}
|
|
}
|