Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f8812b2

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

File tree

2 files changed

+9
-1
lines changed
Filter options

2 files changed

+9
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/FieldType.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/Form/Extension/Core/Type/FieldTypeTest.php
+8Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.