Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Form] LetTextType
implementDataTransformerInterface
#18357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Symfony\Component\Form\Tests\Extension\Core\Type; | ||
use Symfony\Component\Form\Test\TypeTestCase as TestCase; | ||
class TextTypeTest extends TestCase | ||
{ | ||
public function testSubmitNullReturnsNull() | ||
{ | ||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TextType', 'name'); | ||
$form->submit(null); | ||
$this->assertNull($form->getData()); | ||
} | ||
public function testSubmitNullReturnsEmptyStringWithEmptyDataAsString() | ||
{ | ||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TextType', 'name', array( | ||
'empty_data' => '', | ||
)); | ||
$form->submit(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. is there any config with the new system that allows one to distinguish between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. @backbone87 I don't really understand what is "new" for you, as I am feeling quite new myself in symfony :)
ConclusionThis PR could add a view data transformer toprevent that call but I guess in order to prevent messing with other transformers and as this has to stay the default,@webmozart asked to add it as a model data transformer since it is the first registered => also the last called => minimum of potential BC breaks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. with "new system" i was refering to the state of the form component after your PR. i was specially talking about how to distinguish between a text field that is submitted with null vs submitted with empty string. consider a simple form with text field: $form =$factory->create();$form->add('name', TextType::class, ['required' =>false ]); and now the different submits: // 1.$form->submit(null);assert$form->get('name')->getData() ===null;// 2.$form->submit([]);assert$form->get('name')->getData() ===null;// 3.$form->submit(['name' =>null ]);assert$form->get('name')->getData() ===null;// 4.$form->submit(['name' =>'' ]);assert$form->get('name')->getData() ==='';// 5.$form->submit(['name' =>'Joe' ]);assert$form->get('name')->getData() ==='Joe';
edit: this topic isnt directly related to your PR, but a general: "how does the TextType field work currently and is expected to work ideally". i mean there must be a reasoning to kill the empty string from the model value space of the text type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. @backbone87 Yes, the reasoning is to not break data transformers by passing Concerning This is a bug fix, I'm not sure it should go in master though. ping@webmozart | ||
$this->assertSame('', $form->getData()); | ||
} | ||
} |