add builer block context

This commit is contained in:
Simon Vieille 2024-05-15 18:18:56 +02:00
parent b680946daf
commit 7c124008c0
Signed by: deblan
GPG key ID: 579388D585F70417
2 changed files with 18 additions and 17 deletions

View file

@ -135,19 +135,6 @@ abstract class BuilderBlock
return $this->template;
}
public function toArray(): array
{
return [
'label' => $this->getLabel(),
'category' => $this->getCategory(),
'isContainer' => $this->getIsContainer(),
'widgets' => $this->getWidgets(),
'settings' => $this->getSettings(),
'class' => $this->getClass(),
'icon' => $this->getIcon(),
];
}
public function setClass(?string $class): self
{
$this->class = $class;
@ -184,7 +171,7 @@ abstract class BuilderBlock
return $this->order;
}
public function buildVars(array $data)
public function buildVars(array $data, array $context)
{
}
@ -192,4 +179,17 @@ abstract class BuilderBlock
{
return $this->vars;
}
public function toArray(): array
{
return [
'label' => $this->getLabel(),
'category' => $this->getCategory(),
'isContainer' => $this->getIsContainer(),
'widgets' => $this->getWidgets(),
'settings' => $this->getSettings(),
'class' => $this->getClass(),
'icon' => $this->getIcon(),
];
}
}

View file

@ -23,7 +23,7 @@ class BuilderExtension extends AbstractExtension
];
}
public function buildHtml($data): string
public function buildHtml(?array $data, array $context = []): string
{
if (null === $data) {
return null;
@ -35,19 +35,20 @@ class BuilderExtension extends AbstractExtension
}
$widget = $this->container->getWidget($data['widget']);
$widget->buildVars($data);
$widget->buildVars($data, $context);
return $this->twig->render($widget->getTemplate(), [
'id' => $data['id'],
'settings' => $data['settings'],
'children' => $data['children'],
'context' => $context,
'vars' => $widget->getVars(),
]);
}
$render = '';
foreach ($data as $item) {
$render .= $this->buildHtml($item);
$render .= $this->buildHtml($item, $context);
}
return $render;