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

+1-1
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

+8
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)