mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-07 22:49:42 +00:00
Refactor Twig extensions to use attributes for declaring functions and filters, remove AbstractExtension inheritance, and clean up related service definitions.
This commit is contained in:
@@ -22,7 +22,7 @@ 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
|
||||
class CustomFieldRenderingTwig
|
||||
{
|
||||
/**
|
||||
* @var array<string, string> The default parameters
|
||||
@@ -33,29 +33,6 @@ class CustomFieldRenderingTwig extends AbstractExtension
|
||||
|
||||
public function __construct(private readonly CustomFieldsHelper $customFieldsHelper) {}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc).
|
||||
*
|
||||
* @see Twig_Extension::getFunctions()
|
||||
*/
|
||||
#[\Override]
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new TwigFunction('chill_custom_field_widget', $this->renderWidget(...), [
|
||||
'is_safe' => [
|
||||
'html',
|
||||
],
|
||||
]),
|
||||
new TwigFunction('chill_custom_field_label', $this->renderLabel(...), [
|
||||
'is_safe' => [
|
||||
'html',
|
||||
],
|
||||
'needs_environment' => true,
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
/** (non-PHPdoc).
|
||||
* @see Twig_ExtensionInterface::getName()
|
||||
*/
|
||||
@@ -79,6 +56,9 @@ class CustomFieldRenderingTwig extends AbstractExtension
|
||||
*
|
||||
* @return string HTML representation of the custom field label
|
||||
*/
|
||||
#[\Twig\Attribute\AsTwigFunction('chill_custom_field_label', isSafe: [
|
||||
'html',
|
||||
], needsEnvironment: true)]
|
||||
public function renderLabel(Environment $env, CustomField $customField, array $params = []): string
|
||||
{
|
||||
$resolvedParams = array_merge($this->defaultParams, $params);
|
||||
@@ -97,6 +77,9 @@ class CustomFieldRenderingTwig extends AbstractExtension
|
||||
*
|
||||
* @return string HTML representation of the custom field value, as described in the CustomFieldInterface. Is HTML safe
|
||||
*/
|
||||
#[\Twig\Attribute\AsTwigFunction('chill_custom_field_widget', isSafe: [
|
||||
'html',
|
||||
])]
|
||||
public function renderWidget(array $fields, CustomField $customField, $documentType = 'html')
|
||||
{
|
||||
return $this->customFieldsHelper
|
||||
|
||||
Reference in New Issue
Block a user