[Form] Fixed "label" option to accept the value "0"

This commit is contained in:
Bernhard Schussek 2013-02-21 18:06:34 +01:00
parent cf15198faa
commit f8812b28f3
2 changed files with 9 additions and 1 deletions

View File

@ -52,7 +52,7 @@ class FieldType extends AbstractType
->setAttribute('error_mapping', $options['error_mapping'])
->setAttribute('max_length', $options['max_length'])
->setAttribute('pattern', $options['pattern'])
->setAttribute('label', $options['label'] ?: $this->humanize($builder->getName()))
->setAttribute('label', strlen($options['label']) > 0 ? $options['label'] : $this->humanize($builder->getName()))
->setAttribute('attr', $options['attr'] ?: array())
->setAttribute('invalid_message', $options['invalid_message'])
->setAttribute('invalid_message_parameters', $options['invalid_message_parameters'])

View File

@ -238,4 +238,12 @@ class FieldTypeTest extends TypeTestCase
$form = $this->factory->create('field', null, array('attr' => ''));
}
// https://github.com/symfony/symfony/issues/6862
public function testPassZeroLabelToView()
{
$view = $this->factory->create('field', null, array('label' => 0))->createView();
$this->assertEquals('0', $view->get('label'));
}
}