add builer block context
This commit is contained in:
parent
b680946daf
commit
7c124008c0
|
@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue