mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
This commit is contained in:
parent
2fee88bfce
commit
1cf0e51e9a
@ -24,28 +24,33 @@ use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class ChillEntityRenderExtension
|
||||
*
|
||||
* @package Chill\MainBundle\Templating\Entity
|
||||
*/
|
||||
class ChillEntityRenderExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ChillEntityRenderInterface
|
||||
*/
|
||||
protected $renders = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ChillEntityRender
|
||||
*/
|
||||
protected $defaultRender;
|
||||
|
||||
/**
|
||||
* ChillEntityRenderExtension constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->defaultRender = new ChillEntityRender();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|TwigFilter[]
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
@ -58,31 +63,47 @@ class ChillEntityRenderExtension extends AbstractExtension
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $entity
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function renderString($entity, array $options = []): string
|
||||
{
|
||||
if (NULL === $entity) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->getRender($entity, $options)
|
||||
->renderString($entity, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $entity
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function renderBox($entity, array $options = []): string
|
||||
{
|
||||
if (NULL === $entity) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->getRender($entity, $options)
|
||||
->renderBox($entity, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ChillEntityRenderInterface $render
|
||||
*/
|
||||
public function addRender(ChillEntityRenderInterface $render)
|
||||
{
|
||||
$this->renders[] = $render;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $entity
|
||||
* @param $options
|
||||
* @return ChillEntityRenderInterface|null
|
||||
*/
|
||||
protected function getRender($entity, $options): ?ChillEntityRenderInterface
|
||||
{
|
||||
foreach ($this->renders as $render) {
|
||||
@ -90,7 +111,6 @@ class ChillEntityRenderExtension extends AbstractExtension
|
||||
return $render;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->defaultRender;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user