8000 [Form] Improved labels generated by default from form names · symfony/symfony@6584721 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6584721

Browse files
committed
[Form] Improved labels generated by default from form names
1 parent 6e0b03a commit 6584721

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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/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