|
@@ -14,6 +14,7 @@ namespace Symfony\Bridge\Twig\Extension;
|
|
|
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
|
|
|
use Symfony\Component\Form\FormView;
|
|
|
use Symfony\Component\Form\Exception\FormException;
|
|
|
+use Symfony\Component\Form\Util\FormUtil;
|
|
|
|
|
|
/**
|
|
|
* FormExtension extends Twig with form capabilities.
|
|
@@ -74,15 +75,27 @@ class FormExtension extends \Twig_Extension
|
|
|
public function getFunctions()
|
|
|
{
|
|
|
return array(
|
|
|
- 'form_enctype' => new \Twig_Function_Method($this, 'renderEnctype', array('is_safe' => array('html'))),
|
|
|
- 'form_widget' => new \Twig_Function_Method($this, 'renderWidget', array('is_safe' => array('html'))),
|
|
|
- 'form_errors' => new \Twig_Function_Method($this, 'renderErrors', array('is_safe' => array('html'))),
|
|
|
- 'form_label' => new \Twig_Function_Method($this, 'renderLabel', array('is_safe' => array('html'))),
|
|
|
- 'form_row' => new \Twig_Function_Method($this, 'renderRow', array('is_safe' => array('html'))),
|
|
|
- 'form_rest' => new \Twig_Function_Method($this, 'renderRest', array('is_safe' => array('html'))),
|
|
|
+ 'form_enctype' => new \Twig_Function_Method($this, 'renderEnctype', array('is_safe' => array('html'))),
|
|
|
+ 'form_widget' => new \Twig_Function_Method($this, 'renderWidget', array('is_safe' => array('html'))),
|
|
|
+ 'form_errors' => new \Twig_Function_Method($this, 'renderErrors', array('is_safe' => array('html'))),
|
|
|
+ 'form_label' => new \Twig_Function_Method($this, 'renderLabel', array('is_safe' => array('html'))),
|
|
|
+ 'form_row' => new \Twig_Function_Method($this, 'renderRow', array('is_safe' => array('html'))),
|
|
|
+ 'form_rest' => new \Twig_Function_Method($this, 'renderRest', array('is_safe' => array('html'))),
|
|
|
+ '_form_is_choice_group' => new \Twig_Function_Method($this, 'isChoiceGroup', array('is_safe' => array('html'))),
|
|
|
+ '_form_is_choice_selected' => new \Twig_Function_Method($this, 'isChoiceSelected', array('is_safe' => array('html'))),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public function isChoiceGroup($label)
|
|
|
+ {
|
|
|
+ return FormUtil::isChoiceGroup($label);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function isChoiceSelected(FormView $view, $choice)
|
|
|
+ {
|
|
|
+ return FormUtil::isChoiceSelected($choice, $view->get('value'));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Renders the HTML enctype in the form tag, if necessary
|
|
|
*
|