Skip to content

Commit f8812b2

Browse files
committed
[Form] Fixed "label" option to accept the value "0"
1 parent cf15198 commit f8812b2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Symfony/Component/Form/Extension/Core/Type/FieldType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function buildForm(FormBuilder $builder, array $options)
5252
->setAttribute('error_mapping', $options['error_mapping'])
5353
->setAttribute('max_length', $options['max_length'])
5454
->setAttribute('pattern', $options['pattern'])
55-
->setAttribute('label', $options['label'] ?: $this->humanize($builder->getName()))
55+
->setAttribute('label', strlen($options['label']) > 0 ? $options['label'] : $this->humanize($builder->getName()))
5656
->setAttribute('attr', $options['attr'] ?: array())
5757
->setAttribute('invalid_message', $options['invalid_message'])
5858
->setAttribute('invalid_message_parameters', $options['invalid_message_parameters'])

tests/Symfony/Tests/Component/Form/Extension/Core/Type/FieldTypeTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,12 @@ public function testAttributesException()
238238
$form = $this->factory->create('field', null, array('attr' => ''));
239239
}
240240

241+
// https://github.com/symfony/symfony/issues/6862
242+
public function testPassZeroLabelToView()
243+
{
244+
$view = $this->factory->create('field', null, array('label' => 0))->createView();
245+
246+
$this->assertEquals('0', $view->get('label'));
247+
}
248+
241249
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy