-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[DomCrawler] Add hint about Form::getName method #11705
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
Conversation
41ed748
to
36ced8b
Compare
…JustBlackBird) This PR was squashed before being merged into the 4.4 branch (closes #31959). Discussion ---------- [DomCrawler][Feature][DX] Add Form::getName() method | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | None | License | MIT | Doc PR | symfony/symfony-docs#11705 The PR adds `Symfony\Component\DomCrawler\Form::getName` method. The method is actually a syntax sugar but can improve DX when dealing with tests. For example, in the snippet ```php $client = static::createClient(); $crawler = $client->request('GET', '/post/hello-world'); $form = $crawler->selectButton('submit')->form(); $form['my_form[name]'] = 'Fabien'; $form['my_form[subject]'] = 'Symfony rocks!'; ``` the prefix in field name (`my_form`) is form name, which is generated by Symfony automatically. The method, added in the PR helps to get that name in a most obvious way. Commits ------- ff53cb4 [DomCrawler][Feature][DX] Add Form::getName() method
…JustBlackBird) This PR was squashed before being merged into the 4.4 branch (closes #31959). Discussion ---------- [DomCrawler][Feature][DX] Add Form::getName() method | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | None | License | MIT | Doc PR | symfony/symfony-docs#11705 The PR adds `Symfony\Component\DomCrawler\Form::getName` method. The method is actually a syntax sugar but can improve DX when dealing with tests. For example, in the snippet ```php $client = static::createClient(); $crawler = $client->request('GET', '/post/hello-world'); $form = $crawler->selectButton('submit')->form(); $form['my_form[name]'] = 'Fabien'; $form['my_form[subject]'] = 'Symfony rocks!'; ``` the prefix in field name (`my_form`) is form name, which is generated by Symfony automatically. The method, added in the PR helps to get that name in a most obvious way. Commits ------- ff53cb462a [DomCrawler][Feature][DX] Add Form::getName() method
testing.rst
Outdated
@@ -801,6 +801,12 @@ their type:: | |||
$form['my_form[field][O]']->upload('/path/to/lucas.jpg'); | |||
$form['my_form[field][1]']->upload('/path/to/lisa.jpg'); | |||
|
|||
.. tip:: | |||
|
|||
All field names in forms generated by symfony are prefixed with form's name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All field names in forms generated by symfony are prefixed with form's name. | |
All field names in forms generated by Symfony are prefixed with the form's name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OskarStark fixed
36ced8b
to
c8a6ec5
Compare
.. tip:: | ||
|
||
All field names in forms generated by Symfony are prefixed with the form's name. | ||
If the name is autogenerated you can get it using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds misleading IMO. For the method it doesn't really matter how the name originates. Maybe we should reword it to something like this:
Use the
getName()
method if you need to access the name of a form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name of the field is not that obvious on the first sight, so I believe a hint is needed to make it clear. Also, using getName
method in tests can make them a little less fragile.
…ackBird) This PR was merged into the 4.4 branch. Discussion ---------- [DomCrawler] Add hint about Form::getName method This PR describes some use cases of `Symfony\Component\DomCrawler\Form::getName` method Commits ------- c8a6ec5 [DomCrawler] Add hint about Form::getName method
Dmitriy, thanks a lot for contributing this nice little feature and thanks for providing the docs too! We merged it with some very minor rewords as proposed by @xabbuh. Congrats on your first Symfony Docs contribution! |
This PR describes some use cases of
Symfony\Component\DomCrawler\Form::getName
method