|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 .= '';
}
continue;
}
$rendered = $this->renderWidget($widget, $context, $position === 0);
if ($rendered !== '') {
$html .= $rendered;
$position++;
}
}
return new HtmlString($html);
}
/**
* Ob die Instanz randlos dargestellt werden darf (siehe WidgetType::bleeds).
*
* @param array $widget aktuelle Hülle
*/
public function bleeds(array $widget): bool
{
return $this->registry->has((string) ($widget['type'] ?? '')) && $this->registry->get($widget['type'])->bleeds($widget);
}
/**
* Rendert eine Instanz samt Abschnittshülle. Liefert '' wenn das Widget nichts darzustellen hat.
*
* @param array $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'],
'first' => $first,
'context' => $context,
] + $type->resolve($widget, $context))->render());
if ($inner === '') {
return '';
}
$id = is_string($widget['id'] ?? null) ? ' id="abschnitt-'.e($widget['id']).'"' : '';
return '';
}
}