merged branch 77web/fix-form-renderer-humanize (PR #6992)
This PR was squashed before being merged into the master branch (closes #6992).
Commits
-------
8adb0e3
[Form]fixed FormRenderer::humanize() to humanize camel cased label
Discussion
----------
[Form]fixed FormRenderer::humanize() to humanize camel cased label
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | N/A
| License | MIT
| Doc PR | N/A
FormRenderer::humanize() only converts underscored_field_name to humanized field name(just the same as sfInflector::humanize()).
Sensio\Bundle\GeneratorBundle\Generator\DoctrineFormGenerator does not convert camelCased field names to underscored one, however.
I have to edit manually field names in the generated FormType class everytime I use doctrine:generate:form Command, too messy.
so I suggest humanize() is to take care of it.
---------------------------------------------------------------------------
by 77web at 2013-02-08T01:40:59Z
@vicb thank you for your kind review. I've added commits as you told.
---------------------------------------------------------------------------
by vicb at 2013-02-08T07:33:47Z
@77web you probably could merge the the setup into the test method.
---------------------------------------------------------------------------
by 77web at 2013-02-08T08:17:10Z
@vicb I've merged setUp() and tearDown() into test method(before and after assertion). anything else to fix?
---------------------------------------------------------------------------
by 77web at 2013-02-08T10:11:51Z
@vicb I've fixed test as you told.thanks again for your kind help!
---------------------------------------------------------------------------
by vicb at 2013-02-08T12:00:29Z
One last thing: a note in the changelog ?
---------------------------------------------------------------------------
by 77web at 2013-02-08T12:23:57Z
I added a note in 2.2.0 section. or shold I write it in 2.1.0?
---------------------------------------------------------------------------
by vicb at 2013-02-08T12:25:36Z
As you send it to master, you should create a 2.3.0 (2.1 & 2.2 have their own branches)
---------------------------------------------------------------------------
by vicb at 2013-02-08T12:26:40Z
and should write your comment as "fixed xyz to abc". Thanks.
---------------------------------------------------------------------------
by 77web at 2013-02-08T12:32:39Z
fixed my note. thanks a lot! @vicb
This commit is contained in:
commit
30357d6096
@ -1,6 +1,12 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
|
||||||
|
2.3.0
|
||||||
|
------
|
||||||
|
|
||||||
|
* changed FormRenderer::humanize() to humanize also camel cased field name
|
||||||
|
|
||||||
2.2.0
|
2.2.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -280,6 +280,6 @@ class FormRenderer implements FormRendererInterface
|
|||||||
*/
|
*/
|
||||||
public function humanize($text)
|
public function humanize($text)
|
||||||
{
|
{
|
||||||
return ucfirst(trim(strtolower(preg_replace('/[_\s]+/', ' ', $text))));
|
return ucfirst(trim(strtolower(preg_replace(array('/([A-Z])/', '/[_\s]+/'), array('_$1', ' '), $text))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
src/Symfony/Component/Form/Tests/FormRendererTest.php
Normal file
18
src/Symfony/Component/Form/Tests/FormRendererTest.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Form\Test;
|
||||||
|
|
||||||
|
class FormRendererTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testHumanize()
|
||||||
|
{
|
||||||
|
$renderer = $this->getMockBuilder('Symfony\Component\Form\FormRenderer')
|
||||||
|
->setMethods(null)
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock()
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertEquals('Is active', $renderer->humanize('is_active'));
|
||||||
|
$this->assertEquals('Is active', $renderer->humanize('isActive'));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user