diff --git a/src/core/BuilderBlock/BuilderBlock.php b/src/core/BuilderBlock/BuilderBlock.php index d323cf2..069f1da 100644 --- a/src/core/BuilderBlock/BuilderBlock.php +++ b/src/core/BuilderBlock/BuilderBlock.php @@ -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(), + ]; + } } diff --git a/src/core/Twig/Extension/BuilderExtension.php b/src/core/Twig/Extension/BuilderExtension.php index b4671b3..d436608 100644 --- a/src/core/Twig/Extension/BuilderExtension.php +++ b/src/core/Twig/Extension/BuilderExtension.php @@ -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;