allow buildHtml to get null, array or string
This commit is contained in:
parent
25efd11ea3
commit
b9566853ef
|
@ -23,15 +23,23 @@ class BuilderExtension extends AbstractExtension
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildHtml(?array $data, array $context = []): string
|
public function buildHtml(null|array|string $data, array $context = []): ?string
|
||||||
{
|
{
|
||||||
if (null === $data) {
|
if (null === $data) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_string($data)) {
|
||||||
|
$data = json_decode($data, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_array($data)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($data['widget'])) {
|
if (isset($data['widget'])) {
|
||||||
if (!$this->container->hasWidget($data['widget'])) {
|
if (!$this->container->hasWidget($data['widget'])) {
|
||||||
return '';
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$widget = $this->container->getWidget($data['widget']);
|
$widget = $this->container->getWidget($data['widget']);
|
||||||
|
|
Loading…
Reference in a new issue