From 81b7b491701bbdc6382bab2e7184f9a25f989ef3 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 16 Feb 2022 15:23:32 +0100 Subject: [PATCH] ChillEntityRenderExtension: change the way the service in constructed by using tags --- .../ChillMainBundle/ChillMainBundle.php | 1 - .../Entity/ChillEntityRenderExtension.php | 11 ++----- .../Templating/Entity/CompilerPass.php | 31 ------------------- .../config/services/templating.yaml | 2 ++ .../ChillPersonBundle/ChillPersonBundle.php | 3 ++ 5 files changed, 8 insertions(+), 40 deletions(-) delete mode 100644 src/Bundle/ChillMainBundle/Templating/Entity/CompilerPass.php diff --git a/src/Bundle/ChillMainBundle/ChillMainBundle.php b/src/Bundle/ChillMainBundle/ChillMainBundle.php index 07daf65ea..c18e17918 100644 --- a/src/Bundle/ChillMainBundle/ChillMainBundle.php +++ b/src/Bundle/ChillMainBundle/ChillMainBundle.php @@ -70,7 +70,6 @@ class ChillMainBundle extends Bundle $container->addCompilerPass(new MenuCompilerPass()); $container->addCompilerPass(new ACLFlagsCompilerPass()); $container->addCompilerPass(new GroupingCenterCompilerPass()); - $container->addCompilerPass(new RenderEntityCompilerPass()); $container->addCompilerPass(new CRUDControllerCompilerPass()); } } diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/ChillEntityRenderExtension.php b/src/Bundle/ChillMainBundle/Templating/Entity/ChillEntityRenderExtension.php index e1eae3884..c7de92208 100644 --- a/src/Bundle/ChillMainBundle/Templating/Entity/ChillEntityRenderExtension.php +++ b/src/Bundle/ChillMainBundle/Templating/Entity/ChillEntityRenderExtension.php @@ -25,21 +25,17 @@ class ChillEntityRenderExtension extends AbstractExtension protected $defaultRender; /** - * @var ChillEntityRenderInterface + * @var iterable|ChillEntityRenderInterface[] */ protected $renders = []; /** * ChillEntityRenderExtension constructor. */ - public function __construct() + public function __construct(iterable $renders) { $this->defaultRender = new ChillEntityRender(); - } - - public function addRender(ChillEntityRenderInterface $render) - { - $this->renders[] = $render; + $this->renders = $renders; } /** @@ -78,7 +74,6 @@ class ChillEntityRenderExtension extends AbstractExtension if (null === $entity) { return ''; } - return $this->getRender($entity, $options) ->renderString($entity, $options); } diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/CompilerPass.php b/src/Bundle/ChillMainBundle/Templating/Entity/CompilerPass.php deleted file mode 100644 index 38f6284ca..000000000 --- a/src/Bundle/ChillMainBundle/Templating/Entity/CompilerPass.php +++ /dev/null @@ -1,31 +0,0 @@ -getDefinition(ChillEntityRenderExtension::class); - - foreach ($container->findTaggedServiceIds('chill.render_entity') as $id => $tags) { - $extension->addMethodCall('addRender', [new Reference($id)]); - } - } -} diff --git a/src/Bundle/ChillMainBundle/config/services/templating.yaml b/src/Bundle/ChillMainBundle/config/services/templating.yaml index ade26b946..e69700732 100644 --- a/src/Bundle/ChillMainBundle/config/services/templating.yaml +++ b/src/Bundle/ChillMainBundle/config/services/templating.yaml @@ -32,6 +32,8 @@ services: - { name: twig.extension } Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension: + arguments: + $renders: !tagged_iterator chill.render_entity tags: - { name: twig.extension } diff --git a/src/Bundle/ChillPersonBundle/ChillPersonBundle.php b/src/Bundle/ChillPersonBundle/ChillPersonBundle.php index 4e73d2137..5ab96effe 100644 --- a/src/Bundle/ChillPersonBundle/ChillPersonBundle.php +++ b/src/Bundle/ChillPersonBundle/ChillPersonBundle.php @@ -25,6 +25,9 @@ class ChillPersonBundle extends Bundle $container->getExtension('chill_main') ->addWidgetFactory(new PersonListWidgetFactory()); + $container->registerForAutoconfiguration(PersonRenderInterface::class) + ->addTag('chill.render_entity'); + $container->addCompilerPass(new AccompanyingPeriodTimelineCompilerPass()); } }