merged branch bschussek/issue3738 (PR #3807)

Commits
-------

6584721 [Form] Improved labels generated by default from form names
6e0b03a [Form] Fixed label of prototype in CollectionType
fc342d1 Merge remote branch 'umpirsky/collection-name' into issue3738
f91660d Added test for prototype label.

Discussion
----------

[Form] Fixed default label generated for the CollectionType prototype

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #3738, #3739
Todo: -

![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue3738)

(the fact that the build fails seems to origin from the broken master)
This commit is contained in:
Fabien Potencier 2012-04-07 08:15:43 +02:00
commit 526fb7bf05
4 changed files with 32 additions and 2 deletions

View File

@ -26,7 +26,9 @@ class CollectionType extends AbstractType
public function buildForm(FormBuilder $builder, array $options)
{
if ($options['allow_add'] && $options['prototype']) {
$prototype = $builder->create($options['prototype_name'], $options['type'], $options['options']);
$prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array(
'label' => $options['prototype_name'] . 'label__',
), $options['options']));
$builder->setAttribute('prototype', $prototype->getForm());
}

View File

@ -200,6 +200,6 @@ class FieldType extends AbstractType
private function humanize($text)
{
return ucfirst(strtolower(str_replace('_', ' ', $text)));
return ucfirst(trim(strtolower(preg_replace('/[_\s]+/', ' ', $text))));
}
}

View File

@ -185,4 +185,16 @@ class CollectionTypeTest extends TypeTestCase
$this->assertSame('__test__', $form->getAttribute('prototype')->getName());
}
public function testPrototypeDefaultLabel()
{
$form = $this->factory->create('collection', array(), array(
'type' => 'file',
'allow_add' => true,
'prototype' => true,
'prototype_name' => '__test__',
));
$this->assertSame('__test__label__', $form->createView()->get('prototype')->get('label'));
}
}

View File

@ -188,6 +188,22 @@ class FieldTypeTest extends TypeTestCase
$this->assertSame('test', $view->get('translation_domain'));
}
public function testPassDefaultLabelToView()
{
$form = $this->factory->createNamed('field', '__test___field');
$view = $form->createView();
$this->assertSame('Test field', $view->get('label'));
}
public function testPassLabelToView()
{
$form = $this->factory->createNamed('field', '__test___field', null, array('label' => 'My label'));
$view = $form->createView();
$this->assertSame('My label', $view->get('label'));
}
public function testDefaultTranslationDomain()
{
$form = $this->factory->create('field');