8000 merged branch bschussek/issue3738 (PR #3807) · symfony/symfony@526fb7b · GitHub
[go: up one dir, main page]

Skip to content

Commit 526fb7b

Browse files
committed
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)
2 parents 048f8da + 6584721 commit 526fb7b

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class CollectionType extends AbstractType
2626
public function buildForm(FormBuilder $builder, array $options)
2727
{
2828
if ($options['allow_add'] && $options['prototype']) {
29-
$prototype = $builder->create($options['prototype_name'], $options['type'], $options['options']);
29+
$prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array(
30+
'label' => $options['prototype_name'] . 'label__',
31+
), $options['options']));
3032
$builder->setAttribute('prototype', $prototype->getForm());
3133
}
3234

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,6 @@ public function getName()
200200

201201
private function humanize($text)
202202
{
203-
return ucfirst(strtolower(str_replace('_', ' ', $text)));
203+
return ucfirst(trim(strtolower(preg_replace('/[_\s]+/', ' ', $text))));
204204
}
205205
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,16 @@ public function testPrototypeNameOption()
185185

186186
$this->assertSame('__test__', $form->getAttribute('prototype')->getName());
187187
}
188+
189+
public function testPrototypeDefaultLabel()
190+
{
191+
$form = $this->factory->create('collection', array(), array(
192+
'type' => 'file',
193+
'allow_add' => true,
194+
'prototype' => true,
195+
'prototype_name' => '__test__',
196+
));
197+
198+
$this->assertSame('__test__label__', $form->createView()->get('prototype')->get('label'));
199+
}
188200
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/FieldTypeTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,22 @@ public function testPassTranslationDomainToView()
188188
$this->assertSame('test', $view->get('translation_domain'));
189189
}
190190

191+
public function testPassDefaultLabelToView()
192+
{
193+
$form = $this->factory->createNamed('field', '__test___field');
194+
$view = $form->createView();
195+
196+
$this->assertSame('Test field', $view->get('label'));
197+
}
198+
199+
public function testPassLabelToView()
200+
{
201+
$form = $this->factory->createNamed('field', '__test___field', null, array('label' => 'My label'));
202+
$view = $form->createView();
203+
204+
$this->assertSame('My label', $view->get('label'));
205+
}
206+
191207
public function testDefaultTranslationDomain()
192208
{
193209
$form = $this->factory->create('field');

0 commit comments

Comments
 (0)
0