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;
|
use Twig\TwigFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Class ChillEntityRenderExtension
|
||||||
*
|
*
|
||||||
|
* @package Chill\MainBundle\Templating\Entity
|
||||||
*/
|
*/
|
||||||
class ChillEntityRenderExtension extends AbstractExtension
|
class ChillEntityRenderExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var ChillEntityRenderInterface
|
* @var ChillEntityRenderInterface
|
||||||
*/
|
*/
|
||||||
protected $renders = [];
|
protected $renders = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var ChillEntityRender
|
* @var ChillEntityRender
|
||||||
*/
|
*/
|
||||||
protected $defaultRender;
|
protected $defaultRender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ChillEntityRenderExtension constructor.
|
||||||
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->defaultRender = new ChillEntityRender();
|
$this->defaultRender = new ChillEntityRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array|TwigFilter[]
|
||||||
|
*/
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -58,31 +63,47 @@ class ChillEntityRenderExtension extends AbstractExtension
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $entity
|
||||||
|
* @param array $options
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function renderString($entity, array $options = []): string
|
public function renderString($entity, array $options = []): string
|
||||||
{
|
{
|
||||||
if (NULL === $entity) {
|
if (NULL === $entity) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getRender($entity, $options)
|
return $this->getRender($entity, $options)
|
||||||
->renderString($entity, $options);
|
->renderString($entity, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $entity
|
||||||
|
* @param array $options
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function renderBox($entity, array $options = []): string
|
public function renderBox($entity, array $options = []): string
|
||||||
{
|
{
|
||||||
if (NULL === $entity) {
|
if (NULL === $entity) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getRender($entity, $options)
|
return $this->getRender($entity, $options)
|
||||||
->renderBox($entity, $options);
|
->renderBox($entity, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ChillEntityRenderInterface $render
|
||||||
|
*/
|
||||||
public function addRender(ChillEntityRenderInterface $render)
|
public function addRender(ChillEntityRenderInterface $render)
|
||||||
{
|
{
|
||||||
$this->renders[] = $render;
|
$this->renders[] = $render;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $entity
|
||||||
|
* @param $options
|
||||||
|
* @return ChillEntityRenderInterface|null
|
||||||
|
*/
|
||||||
protected function getRender($entity, $options): ?ChillEntityRenderInterface
|
protected function getRender($entity, $options): ?ChillEntityRenderInterface
|
||||||
{
|
{
|
||||||
foreach ($this->renders as $render) {
|
foreach ($this->renders as $render) {
|
||||||
@ -90,7 +111,6 @@ class ChillEntityRenderExtension extends AbstractExtension
|
|||||||
return $render;
|
return $render;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->defaultRender;
|
return $this->defaultRender;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user