From 957ff28221057c9dfc2c7211f9e2858b95729793 Mon Sep 17 00:00:00 2001 From: Garanzha Dmitriy Date: Thu, 28 Mar 2013 17:02:23 +0200 Subject: [PATCH 1/4] add ability to disable choice in form --- src/Symfony/Bridge/Twig/Extension/FormExtension.php | 6 ++++++ .../Resources/views/Form/form_div_layout.html.twig | 2 +- .../Component/Form/Extension/Core/View/ChoiceView.php | 11 ++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index 0609fb675dcf8..aa967b0485061 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -88,6 +88,7 @@ public function getTests() { return array( 'selectedchoice' => new \Twig_Test_Method($this, 'isSelectedChoice'), + 'choicedisabled' => new \Twig_Test_Method($this, 'isChoiceDisabled'), ); } @@ -123,6 +124,11 @@ public function isSelectedChoice(ChoiceView $choice, $selectedValue) return $choice->value === $selectedValue; } + public function isChoiceDisabled(ChoiceView $choice) + { + return $choice->disabled; + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 3ab047c494ad8..579b14ab5604d 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -93,7 +93,7 @@ {{ block('choice_widget_options') }} {% else %} - + {% endif %} {% endfor %} {% endspaceless %} diff --git a/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php b/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php index 97cdd214c28f8..aef612dc7aae0 100644 --- a/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php +++ b/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php @@ -39,17 +39,26 @@ class ChoiceView */ public $label; + /** + * Is choice disabled. + * + * @var Boolean + */ + public $disabled; + /** * Creates a new ChoiceView. * * @param mixed $data The original choice. * @param string $value The view representation of the choice. * @param string $label The label displayed to humans. + * @param string $disabled Is choice disabled. */ - public function __construct($data, $value, $label) + public function __construct($data, $value, $label, $disabled = false) { $this->data = $data; $this->value = $value; $this->label = $label; + $this->disabled = $disabled; } } From 232b50224c19e7b6a1c3edcf4f6f399bf8a6044c Mon Sep 17 00:00:00 2001 From: damour Date: Thu, 28 Mar 2013 22:40:08 +0200 Subject: [PATCH 2/4] =?UTF-8?q?remove=C2=A0useless=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Symfony/Bridge/Twig/Extension/FormExtension.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index aa967b0485061..0609fb675dcf8 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -88,7 +88,6 @@ public function getTests() { return array( 'selectedchoice' => new \Twig_Test_Method($this, 'isSelectedChoice'), - 'choicedisabled' => new \Twig_Test_Method($this, 'isChoiceDisabled'), ); } @@ -124,11 +123,6 @@ public function isSelectedChoice(ChoiceView $choice, $selectedValue) return $choice->value === $selectedValue; } - public function isChoiceDisabled(ChoiceView $choice) - { - return $choice->disabled; - } - /** * {@inheritdoc} */ From f8b770a886b1344cc9fdabf065c4d69187a4cfb5 Mon Sep 17 00:00:00 2001 From: damour Date: Thu, 28 Mar 2013 22:43:04 +0200 Subject: [PATCH 3/4] Update form_div_layout.html.twig --- .../Bridge/Twig/Resources/views/Form/form_div_layout.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 579b14ab5604d..780cd695e6c15 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -93,7 +93,7 @@ {{ block('choice_widget_options') }} {% else %} - + {% endif %} {% endfor %} {% endspaceless %} From a6bf2e91442a16595daaab9c72ac3d12977beb73 Mon Sep 17 00:00:00 2001 From: damour Date: Thu, 28 Mar 2013 22:54:25 +0200 Subject: [PATCH 4/4] add support in the PHP templates --- .../Resources/views/Form/choice_widget_options.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php index a7a9311d51326..e4d53e6b1d829 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php @@ -6,6 +6,6 @@ block($form, 'choice_widget_options', array('choices' => $choice)) ?> - +