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:
49
site/plugins/form/twig/FormTwigExtension.php
Normal file
49
site/plugins/form/twig/FormTwigExtension.php
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user