Skip to content

Add a 2nd argument to create() #9413

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Add a 2nd argument to create() #9413

wants to merge 2 commits into from

Conversation

ismail1432
Copy link
Contributor

Maybe I'm wrong but I tried the exemple with my case and the test failed because IMO if we don't pass an object to second argument, $form->getData() will return an array and this->assertEquals() can't compare an object with an array.
What do you think :-)

Maybe I'm wrong but I tried the exemple with my case and the test failed because IMO if we don't pass an object to second argument, $form->getData() will return an array and this->assertEquals() can't compare an object with an array.
What do you think :-)
@javiereguiluz
Copy link
Member

Let's ask for a review to our Forms expert @vudaltsov Thanks!

@xabbuh
Copy link
Member

xabbuh commented Mar 9, 2018

To be more precise, the type of the returned data depends on whether or not the data_class option is set (see http://symfony.com/doc/current/reference/forms/types/form.html#empty-data). However, passing the data object when creating the form does not harm. So let's do this change. 👍

@xabbuh xabbuh added this to the 2.7 milestone Mar 9, 2018


$objectToCompare = new TestObject();
//$objectToCompare will retrieve data from the form submission pass it at second argument
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space after //

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and 1 space before //, 1 space before $objectToCompare (the indents are incorrect).

$object = new TestObject();
// ...populate $object properties with the data stored in $formData

// submit the data to the form directly
$form->submit($formData);


//Will fill data in $objectToCompare
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually just remove this comment



//Will fill data in $objectToCompare
$objectToCompare = $form->getData();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not introduce this variable here. There is no need for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand but IMO it's strange to declare a variable, pass it as an argument and never use it after.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now we are doing exactly that because we are overwriting the previously declared variable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xabbuh do we need to change anything in the merged PR? If yes, could you please create a quick issue (or PR) to not forget about it? Thanks a lot!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #9431

Copy link
Contributor

@vudaltsov vudaltsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this PR, it's a common practice to use object itself, not $form->getData().

But CS should be fixed.



$objectToCompare = new TestObject();
//$objectToCompare will retrieve data from the form submission pass it at second argument
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and 1 space before //, 1 space before $objectToCompare (the indents are incorrect).

$object = new TestObject();
// ...populate $object properties with the data stored in $formData

// submit the data to the form directly
$form->submit($formData);


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove spaces on an empty line

@ismail1432
Copy link
Contributor Author

Thanks for all feedbacks, I'll work on quickly,

I updated to correct CS
@wouterj
Copy link
Member

wouterj commented Mar 10, 2018

👍 Looks great, thanks!

status: reviewed

@javiereguiluz
Copy link
Member

Thanks for this nice contribution! Help with form docs is always much appreciated! We merged this on 2.7 branch.

javiereguiluz added a commit that referenced this pull request Mar 11, 2018
This PR was submitted for the 4.0 branch but it was squashed and merged into the 2.7 branch instead (closes #9413).

Discussion
----------

Add a 2nd argument to create()

Maybe I'm wrong but I tried the exemple with my case and the test failed because IMO if we don't pass an object to second argument, $form->getData() will return an array and this->assertEquals() can't compare an object with an array.
What do you think :-)

Commits
-------

ecef1fc Add a 2nd argument to create()
@ismail1432
Copy link
Contributor Author

It’s always a pleasure to help us even I’m still waiting for the « Documentation’s Badge contributor » 😜
Enjoy Guys !

xabbuh added a commit to xabbuh/symfony-docs that referenced this pull request Mar 13, 2018
javiereguiluz added a commit that referenced this pull request Mar 13, 2018
This PR was merged into the 2.7 branch.

Discussion
----------

[#9413] some minor tweaks

Commits
-------

a624ca3 [#9413] some minor tweaks
javiereguiluz added a commit to javiereguiluz/symfony-docs that referenced this pull request Mar 13, 2018
* 2.7:
  [symfony#9413] some minor tweaks
  Ask users to create two commits for reproducers
javiereguiluz added a commit to javiereguiluz/symfony-docs that referenced this pull request Mar 13, 2018
* 2.8:
  [symfony#9413] some minor tweaks
  Ask users to create two commits for reproducers
javiereguiluz added a commit to javiereguiluz/symfony-docs that referenced this pull request Mar 13, 2018
* 3.4:
  Adding a documentation page about Bootstrap 4 form theme
  [symfony#9413] some minor tweaks
  Ask users to create two commits for reproducers
  Improved variable naming
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants