simplify to add widgets via plugin (#1308)

This commit is contained in:
Kevin Papst
2019-12-06 23:36:03 +01:00
committed by GitHub
parent 5b0266c462
commit d62e1c4468
4 changed files with 30 additions and 4 deletions

View File

@@ -11,7 +11,6 @@ namespace App\Widget\Renderer;
use App\Widget\Type\SimpleWidget;
use App\Widget\WidgetInterface;
use ReflectionClass;
class SimpleWidgetRenderer extends AbstractTwigRenderer
{
@@ -20,11 +19,18 @@ class SimpleWidgetRenderer extends AbstractTwigRenderer
return $widget instanceof SimpleWidget;
}
/**
* @param SimpleWidget $widget
* @param array $options
* @return string
* @throws \ReflectionException
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function render(WidgetInterface $widget, array $options = []): string
{
$name = (new ReflectionClass($widget))->getShortName();
return $this->renderTemplate(sprintf('widget/widget-%s.html.twig', strtolower($name)), [
return $this->renderTemplate($widget->getTemplateName(), [
'data' => $widget->getData($options),
'options' => $widget->getOptions($options),
'title' => $widget->getTitle(),

View File

@@ -11,4 +11,10 @@ namespace App\Widget\Type;
class SimpleWidget extends AbstractWidgetType
{
public function getTemplateName(): string
{
$name = (new \ReflectionClass($this))->getShortName();
return sprintf('widget/widget-%s.html.twig', strtolower($name));
}
}