mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix usage of twig environment in twig custom fields rendering extensions
This commit is contained in:
parent
dbccf7ff80
commit
e2b500ea5f
@ -16,6 +16,7 @@ use Chill\CustomFieldsBundle\Service\CustomFieldsHelper;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Twig\Environment;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
@ -24,15 +25,14 @@ use Twig\TwigFunction;
|
||||
* * chill_custom_field_widget : to render the value of the custom field,
|
||||
* * chill_custom_field_label : to render the label of the custom field,.
|
||||
*/
|
||||
class CustomFieldRenderingTwig extends AbstractExtension implements ContainerAwareInterface
|
||||
class CustomFieldRenderingTwig extends AbstractExtension
|
||||
{
|
||||
private ?\Symfony\Component\DependencyInjection\ContainerInterface $container = null;
|
||||
|
||||
/**
|
||||
* @var array The default parameters
|
||||
*/
|
||||
private array $defaultParams = [
|
||||
'label_layout' => 'ChillCustomFieldsBundle:CustomField:render_label.html.twig',
|
||||
'label_layout' => '@ChillCustomFields/CustomField/render_label.html.twig',
|
||||
];
|
||||
|
||||
public function __construct(private readonly CustomFieldsHelper $customFieldsHelper)
|
||||
@ -56,6 +56,7 @@ class CustomFieldRenderingTwig extends AbstractExtension implements ContainerAwa
|
||||
'is_safe' => [
|
||||
'html',
|
||||
],
|
||||
'needs_environment' => true,
|
||||
]),
|
||||
new TwigFunction('chill_custom_field_is_empty', $this->isEmptyValue(...)),
|
||||
];
|
||||
@ -83,12 +84,11 @@ class CustomFieldRenderingTwig extends AbstractExtension implements ContainerAwa
|
||||
*
|
||||
* @return string HTML representation of the custom field label.
|
||||
*/
|
||||
public function renderLabel(CustomField $customField, array $params = [])
|
||||
public function renderLabel(Environment $env, CustomField $customField, array $params = [])
|
||||
{
|
||||
$resolvedParams = array_merge($this->defaultParams, $params);
|
||||
|
||||
return $this->container->get('templating')
|
||||
->render($resolvedParams['label_layout'], ['customField' => $customField]);
|
||||
return $env->render($resolvedParams['label_layout'], ['customField' => $customField]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,14 +107,4 @@ class CustomFieldRenderingTwig extends AbstractExtension implements ContainerAwa
|
||||
return $this->customFieldsHelper
|
||||
->renderCustomField($fields, $customField, $documentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc).
|
||||
*
|
||||
* @see \Symfony\Component\DependencyInjection\ContainerAwareInterface::setContainer()
|
||||
*/
|
||||
public function setContainer(?ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ namespace Chill\CustomFieldsBundle\Templating\Twig;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Twig\Environment;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
@ -22,15 +23,13 @@ use Twig\TwigFunction;
|
||||
* * chill_custom_fields_group_widget : to render the value of a custom field
|
||||
* * group.
|
||||
*/
|
||||
class CustomFieldsGroupRenderingTwig extends AbstractExtension implements ContainerAwareInterface
|
||||
final class CustomFieldsGroupRenderingTwig extends AbstractExtension
|
||||
{
|
||||
private ?\Symfony\Component\DependencyInjection\ContainerInterface $container = null;
|
||||
|
||||
/**
|
||||
* @var array The default parameters
|
||||
*/
|
||||
private array $defaultParams = [
|
||||
'layout' => 'ChillCustomFieldsBundle:CustomFieldsGroup:render.html.twig',
|
||||
'layout' => '@ChillCustomFields/CustomFieldsGroup/render.html.twig',
|
||||
'show_empty' => true,
|
||||
];
|
||||
|
||||
@ -54,6 +53,7 @@ class CustomFieldsGroupRenderingTwig extends AbstractExtension implements Contai
|
||||
'is_safe' => [
|
||||
'html',
|
||||
],
|
||||
'needs_environment' => true,
|
||||
]),
|
||||
];
|
||||
}
|
||||
@ -82,24 +82,13 @@ class CustomFieldsGroupRenderingTwig extends AbstractExtension implements Contai
|
||||
* @return string HTML representation of the custom field group value, as described in
|
||||
* the CustomFieldInterface. Is HTML safe
|
||||
*/
|
||||
public function renderWidget(array $fields, $customFielsGroup, $documentType = 'html', array $params = [])
|
||||
public function renderWidget(Environment $env, array $fields, $customFielsGroup, $documentType = 'html', array $params = [])
|
||||
{
|
||||
$resolvedParams = array_merge($this->defaultParams, $params);
|
||||
|
||||
return $this->container->get('templating')
|
||||
->render($resolvedParams['layout'], [
|
||||
'cFGroup' => $customFielsGroup,
|
||||
'cFData' => $fields,
|
||||
'show_empty' => $resolvedParams['show_empty'], ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc).
|
||||
*
|
||||
* @see \Symfony\Component\DependencyInjection\ContainerAwareInterface::setContainer()
|
||||
*/
|
||||
public function setContainer(?ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
return $env->render($resolvedParams['layout'], [
|
||||
'cFGroup' => $customFielsGroup,
|
||||
'cFData' => $fields,
|
||||
'show_empty' => $resolvedParams['show_empty'], ]);
|
||||
}
|
||||
}
|
||||
|
@ -102,15 +102,11 @@ services:
|
||||
class: Chill\CustomFieldsBundle\Templating\Twig\CustomFieldRenderingTwig
|
||||
arguments:
|
||||
- "@chill.custom_field.helper"
|
||||
calls:
|
||||
- [setContainer, ["@service_container"]]
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
|
||||
chill.custom_field.twig.custom_fields_group_rendering:
|
||||
class: Chill\CustomFieldsBundle\Templating\Twig\CustomFieldsGroupRenderingTwig
|
||||
calls:
|
||||
- [setContainer, ["@service_container"]]
|
||||
arguments:
|
||||
- "%chill_custom_fields.show_empty_values%"
|
||||
tags:
|
||||
|
Loading…
x
Reference in New Issue
Block a user