Skip to content

Update the dynamic form article to use modern Symfony practices #9619

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

Merged
merged 1 commit into from
Apr 20, 2018

Conversation

javiereguiluz
Copy link
Member

No description provided.

Copy link
Contributor

@linaori linaori left a comment

Choose a reason for hiding this comment

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

The current changes look correct compared to the old changes.

However, this form assumes that the security user is also an entity. For developers that don't have this, the form might be confusing. I'm also of opinion that if you need the current user, the form should request this via either an option or the data object.

If I look at this form, it looks so complex and big. I do understand why people say that Symfony forms are really complex when looking at this form.

I would personally love to see a very simple form where dynamic form modification is done, which does not need any external dependencies and just focus on the form modification.

@@ -301,13 +298,13 @@ and fill in the listener logic::
$formOptions = array(
'class' => User::class,
'choice_label' => 'fullName',
'query_builder' => function (EntityRepository $er) use ($user) {
'query_builder' => function (EntityRepository $users) use ($user) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not using userRepository ?

It feels strange for a $users variable to not contain a collection of user IMHO.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a new practice that we're slowly introducing in Symfony (and commonly used in other popular projects). We use it for example in the Symfony Demo app: https://github.com/symfony/demo/blob/3c5d376ac8e3f7ae34d972ebb11de9542d0e73ff/src/Controller/BlogController.php#L51 Instead of XxxxRepository $xxxRepository we call it XxxRepository $xxxs because we consider that the code is easier to understand that way.

Copy link
Member Author

Choose a reason for hiding this comment

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

I finally renamed the variable to $userRepository as you asked!

Copy link
Contributor

@Simperfit Simperfit left a comment

Choose a reason for hiding this comment

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

Minor comment

@javiereguiluz javiereguiluz merged commit c45553d into symfony:4.0 Apr 20, 2018
javiereguiluz added a commit that referenced this pull request Apr 20, 2018
…ctices (javiereguiluz)

This PR was squashed before being merged into the 4.0 branch (closes #9619).

Discussion
----------

Update the dynamic form article to use modern Symfony practices

Commits
-------

c45553d Update the dynamic form article to use modern Symfony practices
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.

4 participants