CI Feature / test (push) Failing after 5m29s
Gemeinsamer Vertrag in WidgetType (typography(), paletteTarget()) mit den Einstellungen heading_size, text_size und palette; WidgetAppearance setzt Klassen und Eigenschaften an der Hülle, nur wenn ein Wert gewählt ist. Eine absolute Größenskala aus den Designwerten gilt in jedem Widget gleich; ohne Wahl bleibt die bisherige Größe. Die Palettenfarbe färbt je Art die Fläche des Widgets (hull) oder dessen eigene Fläche (face). Der Verwendungsnachweis der Palette zählt jetzt auch Widgets, damit die Bestätigung einer Farbänderung und die Sperre beim Entfernen greifen. Der Vertragstest für Einstellungsgruppen nimmt die gemeinsamen Schlüssel bewusst aus, weil sie eigene Gruppen im Editor haben. ADR-68, Abnahme unter docs/ux/verwaltung/abnahme/widget-flaeche-schrift.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
89 lines
3.1 KiB
PHP
89 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Cms\Widgets;
|
|
|
|
use App\Domain\Cms\Widgets\Support\WidgetAppearance;
|
|
use Illuminate\Support\HtmlString;
|
|
|
|
/**
|
|
* Einziger Darstellungsweg für Widgets: öffentliche Seite, ganzseitige Vorschau und Blockvorschau im Editor
|
|
* verwenden dieselbe Blade-Ansicht je Widget-Art.
|
|
*/
|
|
class WidgetRenderer
|
|
{
|
|
public function __construct(private readonly WidgetRegistry $registry) {}
|
|
|
|
/**
|
|
* @param array<int|string, mixed>|null $blocks gespeicherte Bausteine (Altformat oder Hülle)
|
|
*/
|
|
public function renderAll(?array $blocks, RenderContext $context): HtmlString
|
|
{
|
|
$html = '';
|
|
$position = 0;
|
|
|
|
foreach (array_values($blocks ?? []) as $block) {
|
|
if (! is_array($block)) {
|
|
continue;
|
|
}
|
|
|
|
$widget = $this->registry->upcast($block);
|
|
|
|
if ($widget === null) {
|
|
if ($context->preview) {
|
|
$html .= '<section class="block widget-unknown"><p class="preview-note">Unbekannter Baustein „'.e((string) ($block['type'] ?? '')).'“ wird öffentlich nicht angezeigt.</p></section>';
|
|
}
|
|
|
|
continue;
|
|
}
|
|
|
|
$rendered = $this->renderWidget($widget, $context, $position === 0);
|
|
|
|
if ($rendered !== '') {
|
|
$html .= $rendered;
|
|
$position++;
|
|
}
|
|
}
|
|
|
|
return new HtmlString($html);
|
|
}
|
|
|
|
/**
|
|
* Rendert eine Instanz samt Abschnittshülle. Liefert '' wenn das Widget nichts darzustellen hat.
|
|
*
|
|
* @param array<string, mixed> $widget aktuelle Hülle
|
|
*/
|
|
public function renderWidget(array $widget, RenderContext $context, bool $first = false): string
|
|
{
|
|
$type = $this->registry->get($widget['type']);
|
|
|
|
$inner = trim(view($type->view(), [
|
|
'widget' => $widget,
|
|
'data' => $widget['data'],
|
|
'refs' => $widget['refs'],
|
|
'variant' => $widget['variant'],
|
|
'settings' => $widget['settings'],
|
|
'height' => $type->height($widget),
|
|
'first' => $first,
|
|
'context' => $context,
|
|
] + $type->resolve($widget, $context))->render());
|
|
|
|
if ($inner === '') {
|
|
return '';
|
|
}
|
|
|
|
$id = is_string($widget['id'] ?? null) ? ' id="abschnitt-'.e($widget['id']).'"' : '';
|
|
|
|
// Gemeinsamer Layoutvertrag (ADR-38): Höhe als Klasse an der Hülle, nur wenn die Art Höhen anbietet.
|
|
$height = $type->height($widget);
|
|
$heightClass = $height !== null ? ' widget-height-'.e($height) : '';
|
|
|
|
// Schriftgrößen und Farbe (ADR-68): Klassen und Eigenschaften nur, wenn ein Wert gesetzt ist; sonst bleibt die Hülle unverändert.
|
|
$appearance = WidgetAppearance::classes($type, $widget['settings']);
|
|
$surface = WidgetAppearance::style($type, $widget['settings']);
|
|
|
|
return '<section class="block widget widget-'.e(str_replace('_', '-', $widget['type'])).' widget-variant-'.e(str_replace('_', '-', $widget['variant'])).$heightClass.$appearance.'"'.$id.$surface.'>'
|
|
.$inner
|
|
.'</section>';
|
|
}
|
|
}
|