ChillEntityRenderExtension: change the way the service in constructed by using tags

This commit is contained in:
nobohan 2022-02-16 15:23:32 +01:00
parent 50410d190f
commit 81b7b49170
5 changed files with 8 additions and 40 deletions

View File

@ -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());
}
}

View File

@ -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);
}

View File

@ -1,31 +0,0 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Templating\Entity;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* Add service tagged with `chill.render_entity` to appropriate service.
*/
class CompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$extension = $container->getDefinition(ChillEntityRenderExtension::class);
foreach ($container->findTaggedServiceIds('chill.render_entity') as $id => $tags) {
$extension->addMethodCall('addRender', [new Reference($id)]);
}
}
}

View File

@ -32,6 +32,8 @@ services:
- { name: twig.extension }
Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension:
arguments:
$renders: !tagged_iterator chill.render_entity
tags:
- { name: twig.extension }

View File

@ -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());
}
}