merged branch bschussek/issue3738 (PR #3807)
Commits -------6584721
[Form] Improved labels generated by default from form names6e0b03a
[Form] Fixed label of prototype in CollectionTypefc342d1
Merge remote branch 'umpirsky/collection-name' into issue3738f91660d
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:
commit
526fb7bf05
@ -26,7 +26,9 @@ class CollectionType extends AbstractType
|
|||||||
public function buildForm(FormBuilder $builder, array $options)
|
public function buildForm(FormBuilder $builder, array $options)
|
||||||
{
|
{
|
||||||
if ($options['allow_add'] && $options['prototype']) {
|
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());
|
$builder->setAttribute('prototype', $prototype->getForm());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,6 +200,6 @@ class FieldType extends AbstractType
|
|||||||
|
|
||||||
private function humanize($text)
|
private function humanize($text)
|
||||||
{
|
{
|
||||||
return ucfirst(strtolower(str_replace('_', ' ', $text)));
|
return ucfirst(trim(strtolower(preg_replace('/[_\s]+/', ' ', $text))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,4 +185,16 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->assertSame('__test__', $form->getAttribute('prototype')->getName());
|
$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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,22 @@ class FieldTypeTest extends TypeTestCase
|
|||||||
$this->assertSame('test', $view->get('translation_domain'));
|
$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()
|
public function testDefaultTranslationDomain()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('field');
|
$form = $this->factory->create('field');
|
||||||
|
Reference in New Issue
Block a user