From 36e455680549bfe9fa5b1282e95bb9b36f2220be Mon Sep 17 00:00:00 2001 From: BenjaminBeck Date: Mon, 3 Sep 2012 12:17:03 +0300 Subject: [PATCH 1/3] [Form] Option for not displaying a label by setting label to false. [Form] Fixed formatting & translation .. --- .../Twig/Resources/views/Form/form_div_layout.html.twig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 0e562e414273f..840fdcda99dbd 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 @@ -227,10 +227,12 @@ {% if required %} {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %} {% endif %} - {% if label is empty %} - {% set label = name|humanize %} + {% if label is not sameas(false) %} + {% if label is empty %} + {% set label = name|humanize %} + {% endif %} + {{ label|trans({}, translation_domain) }} {% endif %} - {{ label|trans({}, translation_domain) }} {% endspaceless %} {% endblock form_label %} From 120547c8bcdc530f00508c0ab3abb3a6e04a2cc6 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Tue, 11 Dec 2012 09:29:21 +0100 Subject: [PATCH 2/3] [Form][TwigBridge] Don't set label attributes if is marked as not to be rendered [Form][FrameworkBundle] Add option to disable rendering of label for fields --- .../Resources/views/Form/form_div_layout.html.twig | 12 ++++++------ .../Resources/views/Form/form_label.html.php | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) 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 840fdcda99dbd..177e6f1e471f3 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 @@ -221,13 +221,13 @@ {% block form_label %} {% spaceless %} - {% if not compound %} - {% set label_attr = label_attr|merge({'for': id}) %} - {% endif %} - {% if required %} - {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %} - {% endif %} {% if label is not sameas(false) %} + {% if not compound %} + {% set label_attr = label_attr|merge({'for': id}) %} + {% endif %} + {% if required %} + {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %} + {% endif %} {% if label is empty %} {% set label = name|humanize %} {% endif %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php index 48dd147a60eed..4ed04cc392f1e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php @@ -1,4 +1,6 @@ + humanize($name); } ?> + From d5426f0a7609d97f5fa52a77be79a1280bddd460 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Tue, 11 Dec 2012 09:37:25 +0100 Subject: [PATCH 3/3] [Form] Add tests to prove that label is not rendered when is marked as false --- .../Form/Tests/AbstractDivLayoutTest.php | 17 +++++++++++++++++ .../Form/Tests/AbstractTableLayoutTest.php | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php index 576d7890da84f..ac9b18b065c97 100644 --- a/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php @@ -526,6 +526,23 @@ public function testLabelHasNoId() ); } + public function testLabelIsNotRenderedWhenSetToFalse() + { + $form = $this->factory->createNamed('name', 'text', null, array( + 'label' => false + )); + $html = $this->renderRow($form->createView()); + + $this->assertMatchesXpath($html, +'/div + [ + ./input[@id="name"] + ] + [count(//label)=0] +' + ); + } + /** * @dataProvider themeBlockInheritanceProvider */ diff --git a/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php index c21c712c5c0d1..efa957fb0b77a 100644 --- a/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php @@ -39,6 +39,25 @@ public function testRow() ); } + public function testLabelIsNotRenderedWhenSetToFalse() + { + $form = $this->factory->createNamed('name', 'text', null, array( + 'label' => false + )); + $html = $this->renderRow($form->createView()); + + $this->assertMatchesXpath($html, +'/tr + [ + ./td + [count(//label)=0] + /following-sibling::td + [./input[@id="name"]] + ] +' + ); + } + public function testRepeatedRow() { $form = $this->factory->createNamed('name', 'repeated');