1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-14 00:54:03 +02:00

feat(form-plugin): add form_render twig function #408

This commit is contained in:
Awilum
2020-03-11 13:20:38 +03:00
parent 1a88662190
commit 26adaae919

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/**
* Flextype (http://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
namespace Flextype;
use Twig_Extension;
use Twig_SimpleFunction;
class FormTwigExtension extends Twig_Extension
{
/**
* Flextype Dependency Container
*/
private $flextype;
/**
* Constructor
*/
public function __construct($flextype)
{
$this->flextype = $flextype;
}
/**
* Returns a list of functions to add to the existing list.
*
* @return array
*/
public function getFunctions() : array
{
return [
new Twig_SimpleFunction('form_render', [$this, 'form_render'], ['is_safe' => ['html']])
];
}
/**
* Form Render
*/
public function form_render(array $fieldset, array $values = []) : string
{
return $this->flextype->FormController->render($fieldset, $values);
}
}