Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Add a data_help method in Form#26332
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.
Conversation
stof left a comment
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 is missing tests
| {%blockform_help -%} | ||
| {%ifform.vars.helpis notempty %} | ||
| <smallclass="form-text text-muted">{{form.vars.help|raw }}</small> |
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.
displaying it raw is a bad idea IMO. It opens the door to XSS.
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.
Mmm, is it really a problem ? Because it's set in the FormType by the dev, not by a user. Then, if we want use html in the help text without raw, we can't. I don't really know
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.
Well, requiring to perform HTML escaping when setting the option is insecure IMO. It requires all devs to be aware that this options requires escaping when setting it. And it might totally be set based on some user input (coming from a previous configuration elsewhere) in some cases.
Btw, I would add translation support for the help text instead of requiring to translate it in the form type when setting the option.
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.
Ok, I remove it from Symfony, if someone want to change it, just to extend the Template and add the raw.
By translation you mean use|trans in Twig ?
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.
yes, as done for labels or other things
| {# Help#} | ||
| {%blockform_help -%} | ||
| {%ifform.vars.helpis notempty %} |
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.
justhelp
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.
Thx for the shortcut, I edit it
mpiot commentedFeb 27, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Yes, I fix existing tests, and wite new (I've never do it, it take a little times, sorry...) |
Nyholm left a comment
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.
Great. Thank you for contributing this.
| {%blockform_help -%} | ||
| {%ifhelpis notempty %} | ||
| <smallclass="form-text text-muted">{{help|trans }}</small> |
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.
Let's make sure it respects the translation domain.
{{ translation_domain is same as(false) ? help : help|trans({}, translation_domain) }}
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.
Okay, I edit it. (I don't really know what is it, but I trust you ;-))
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.
It checks iftranslation_domain is false, it it is we just printhelp. If it is not false we use translation with that domain.
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.
I was thinking about TranslationDomain, I don't know what it is, I'd watch.
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.
Have a look here:http://symfony.com/doc/current/components/translation.html#using-message-domains
It is basically a way to categorize translation messages.
Make sure you add this fix every time you printhelp. (ie in the form_div_layout.html.twig)
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.
Thanks, and it's done :-) (it's interresting to do PR, it permit to learn lot of things:-))
mpiot commentedFeb 27, 2018
Just a question, how can I execute tests ? Because when I do: It return to me alle is ok, but Skip a lot of tests, but in TravisCi, it doesn't skip test and there is a lot of error, I can't try and push everytime to see what say Travis :-( I've try to do something like travis do: But it does less tests, Skip all, and thrw an exception:
Thanks a lot, and sorry, it's the first tim I'm looking into tests... (I know, it's wrong... :p) |
Nyholm commentedFeb 27, 2018
I usually do Here is a page that describes this in details:https://symfony.com/doc/current/contributing/code/tests.html |
Nyholm commentedFeb 27, 2018
Btw, I see that it is the "deps low" test that fails on Travis. That is okey for this PR since the changes on the different components depends on each other. |
mpiot commentedFeb 27, 2018
Oki, but I thought it would be nice to add tests for the new elements, right? Test the |
Nyholm commentedFeb 27, 2018
That would be excellent. |
javiereguiluz commentedFeb 27, 2018
I'm pinging some of our biggest Symfony Form experts so they can double check these changes:@HeahDude,@vudaltsov,@yceruto Thanks! |
mpiot commentedFeb 27, 2018
Thank you :-) |
vudaltsov left a comment
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.
Great PR, I like it.
Since we support Foundation framework, we should probably addform_help there too.
Nyholm commentedFeb 28, 2018
Excellent. This looks real good. There is one thing I'm missing. You need to add an <labelfor="inputPassword5">Password</label><inputtype="password"id="inputPassword5"class="form-control"aria-describedby="passwordHelpBlock"><smallid="passwordHelpBlock"class="form-text text-muted"> Your password must be 8-20 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji.</small> |
mpiot commentedFeb 28, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@Nyholm I fix it tomorrow :-) |
Nyholm commentedMar 1, 2018
Good. We also need the the aria-describedby on the . After that I’m very happy. |
mpiot commentedMar 1, 2018
@Nyholm This is done, just a little reflexion to avoid add the aria-describedBy, when there is not helpBlock. And some difficulties in the FrameworkBundle views, I don't know wwhat is its usage, but I don't like it :p |
Nyholm left a comment
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.
Good job. I did a much more thorough review now.
Could you also make sure fabbot is happy?
| {%blockform_help -%} | ||
| {%ifhelpis notempty %} | ||
| <smallid="{{id }}HelpBlock"class="form-text text-muted">{{translation_domainissame as(false)?help:help|trans({},translation_domain) }}</small> |
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.
id generated by symfony is snake_case. I suggest changing this to{{ id }}_help
| {{- form_label(form) -}} | ||
| {{- form_errors(form) -}} | ||
| {{- form_widget(form) -}} | ||
| {{- form_widget(form, {'helpBlockDisplayed':true }) -}} |
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.
Couldn't we check ifhelp is not empty here?
That would make the logic inwidget_attributes simpler
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.
The problem is when a user just displayform_widget for exemple, theform_help is not call, then we don't have to display the aria-describedBy, because the block doesn't exists.
That's why I do the test later, else, user say if he declare the form_help to do the link between help block and input.
In the row, I do it automatically, because I'm sure the help block is displayed.
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.
I see. Could we try something like:
{{- form_widget(form, { 'helpBlockDisplayed': (help is not empty) }) -}} or that may be a syntax error.
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.
It's the same problem, we can't do it automatically, the help may be set, but don't displayed if the user do:
{{ form_label(form.name) }}{{ form_errors(form.name) }}{{ form_widget(form.name) }}He doesn't callform_label, then help is not displayed, but set in the 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.
Yeah, But it that a problem?
If the user do:
{{ form_label(form.name) }}{{ form_errors(form.name) }}{{ form_widget(form.name) }}Thenno form help will be rendered and noaria-describedBy will be used.
If the user do:
{{ form_label(form.name) }}{{ form_errors(form.name) }}{{ form_widget(form.name) }}{{ form_help(form.name) }}Then form helpwill be rendered but noaria-describedBy will be used.
We should only make sure that the logic is clean and when the user do:
{{ form_row(form.name) }}Then form helpwill be rendered ANDaria-describedBy will be used.
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.
Yes, we can do that, I've do it to permit the user to add thearia-describedBy when don't useform_row. Then, I'm not really sure it's the best way to do, the method must work for all.
| id="{{id }}" name="{{full_name }}" | ||
| {%-ifdisabled %} disabled="disabled"{%endif -%} | ||
| {%-ifrequired %} required="required"{%endif -%} | ||
| {%-ifhelpBlockDisplayedisdefinedandhelpBlockDisplayedandhelpis notempty %} aria-describedby="{{id }}HelpBlock"{%endif -%} |
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.
Replaceand helpBlockDisplayed and withand helpBlockDisplayed same as(true) and
| @@ -0,0 +1,3 @@ | |||
| <?phpif (!empty($help)):?> | |||
| <p id="<?phpecho$view->escape($id)?>HelpBlock" class="help-text"><?phpecho$view->escape(false !==$translation_domain ?$view['translator']->trans($help,array(),$translation_domain) :$help)?></p> | |||
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.
_help instead ofHelpBlock
| id="<?phpecho$view->escape($id)?>" name="<?phpecho$view->escape($full_name)?>"<?phpif ($disabled):?> disabled="disabled"<?phpendif?> | ||
| <?phpif ($required):?> required="required"<?phpendif?> | ||
| <?phpecho$attr ?''.$view['form']->block($form,'attributes') :''?> | ||
| <?phpif (isset($helpBlockDisplayed) &&$helpBlockDisplayed && !empty($help)):?> aria-describedby="<?phpecho$view->escape($id)?>HelpBlock"<?phpendif?> |
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.
&& $helpBlockDisplayed && => && true === $helpBlockDisplayed &&
| 'attr' =>array(), | ||
| 'post_max_size_message' =>'The uploaded file was too large. Please try to upload a smaller file.', | ||
| 'upload_max_size_message' =>$uploadMaxSizeMessage,// internal | ||
| 'help' =>'', |
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.
Should the default be an empty string or null? Spontaneously I would saynull, but Im sure there is a reason you chose the empty string.
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.
I've not test with null... But In the line bellow, we must define the accepted type that is string. That's why I've put an empty string. But Maybe it works well with null, I can try it. Tests will scream if it's not good.
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.
I confirm, if default is null, it trhown error because it expect a string value.
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.
Okey, Could we make it expect a string value and null? Or maybefalse would make more sense.
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.
I can try if I can give him an array of possibilities, but I don't know if it works, I don't know this part of the code.
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.
It's okay :-)
$resolver->setAllowedTypes('help', ['string', 'NULL']);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.
Great
| $this->assertMatchesXpath($html, | ||
| '/span | ||
| [@id="nameHelpBlock"] |
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.
Update id
| $this->assertMatchesXpath($html, | ||
| '/p | ||
| [@id="nameHelpBlock"] |
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.
Update id
mpiot commentedMar 1, 2018
@Nyholm I've fixed some of your suggestions :-) Mmm, "Could you also make sure fabbot is happy?", how I do that ? :p |
Nyholm commentedMar 1, 2018
mpiot commentedMar 1, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Oh yes, I've see that, but the correction, isn't the way used in all the other files... That's why I've not fix it and keep the way used in existing files. |
Nyholm commentedMar 1, 2018
No, you can trust the fabbot. It does only correct/review the files you've edited in this PR. |
mpiot commentedMar 1, 2018
For exemple it say to fix: By: I've not edited other lines, just add one. That's why I've keep the syntax without the It's the same everywhere, it want to add |
Nyholm commentedMar 1, 2018
I guess fabbot has updated its rules since those other lines were added. I think we should follow the recommendations by fabbot in this case. |
Nyholm left a comment
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.
Could you also run the following to fix the license in the file headers:
curl https://fabbot.io/patch/symfony/symfony/26332/80c66414450cbf0148d4fac6288c83a8b72172ae/license.diff | patch -p0| {%blockform_row -%} | ||
| <divclass="form-group{%if (notcompoundorforce_error|default(false))andnotvalid %} has-error{%endif %}"> | ||
| {{- form_label(form) -}} | ||
| {{- form_widget(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.
We should make sure aria-describedby is enabled here
| {%-endif -%} | ||
| <{{element|default('div') }} class="form-group"> | ||
| {{- form_label(form) -}} | ||
| {{- form_widget(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.
We should make sure aria-describedby is enabled here
| <divclass="row"> | ||
| <divclass="large-12 columns{%if (notcompoundorforce_error|default(false))andnotvalid %} error{%endif %}"> | ||
| {{ form_label(form) }} | ||
| {{ form_widget(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.
We should make sure aria-describedby is enabled here
mpiot commentedMar 1, 2018
It bugs.... The diff is empty, the diff file doesn't exists and I've already apply the patch to add the licence header. |
fabpot commentedMar 27, 2018
Thank you@mpiot. |
This PR was merged into the 4.1-dev branch.Discussion----------Add a data_help method in Form| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#26331| License | MIT| Doc PR |symfony/symfony-docs#9361Add a form_help method in twig to display a help message in form. A `help` keyword is added to all FormType to define the message.Commits-------585ca28 Add return type hint859ee03 Revert: remove comment line from twig templatesd723756 Fix some mistakesc74e0dc Use spaceless balises in Twig templates8b937ff Try without try/catch32bf1f6 Test the renderHelp method in all Tests about help to skip them if necessary.437b77e Skip renderHelp test as skipped if not overrided84be70 Update composer files075fcfd [FrameworkBundle] Add widgetAtt to formTable/form_rowf1d13a8 Fix Fabpot.io69ded67 Added form_help on horizontal design and removed special variablefd53bc5 Enable aria-described in row for all Templates98065d3 fabpot.io fixedb95f8 Use array long syntaxaada72c Set help option on nul as defaultf948147 Rename help id (snake_case)77fa317 Fix Test30deaa9 PSR fixbf4d08c Add aria-describedBy on input1f3a15e Rename id058489d Add an id to the help6ea7a20 Remove vars option from form_helpba798df FrameworkBundle Tests4f2581d Use array long syntaxf15bc79 Fix coding standardsc934e49 Add test without help set8094804 Add Tests067c681 Template for table, Foundation and Bootstrap 3d3e3e49 Fix: check translation domain2c2c045 Adapt existant tests831693a Add trans filtere311838 Remove raw filter for help8b97c1b Use a shortcut to acces help var in Twig template1b89f9d Add a template fot div_layoutc8914f5 Add a data_help method in Form
This PR was squashed before being merged into the 4.1 branch (closes#9361).Discussion----------Add help option to FormTypeAdd documentation about the new featuresymfony/symfony#26332Commits-------5bdf708 Add help option to FormType
mhujer commentedMay 27, 2018
Maybe this should be added toUPGRADE-4.1.md as well? Because when you have yourown Form Type Extension to handle |
nicolas-grekas commentedMay 27, 2018
Would you like to open this PR? |
This PR was merged into the 4.1 branch.Discussion----------[Form] mention "help" field option in UPGRADE file| Q | A| ------------- | ---| Branch? | 4.1 <!-- see below -->| Bug fix? | no| New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files -->| BC breaks? | no <!-- seehttps://symfony.com/bc -->| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass? | yes <!-- please add some, will be required by reviewers -->| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->| License | MITWhen you have your own Form Extension to handle help option (e.g. similar to the one mentioned in the [blog post](https://symfony.com/blog/new-in-symfony-4-1-form-field-help)), it starts to render twice in the form after upgrading to 4.1 (where#26332 was added)<!--Write a short README entry for your feature/bugfix here (replace this comment block.)This will help people understand your PR and can be used as a start of the Doc PR.Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch.-->Commits-------744362a update UPGRADE-4.1 for feature#26332 Form field help option
* 4.1: (22 commits) [HttpKernel] Fix restoring trusted proxies in tests Update UPGRADE-4.0.md [Messenger] Fix suggested enqueue adapter package bumped Symfony version to 4.1.1 updated VERSION for 4.1.0 updated CHANGELOG for 4.1.0 Insert correct parameter_bag service in AbstractController Revert "feature#26702 Mark ExceptionInterfaces throwable (ostrolucky)" CODEOWNERS: some more rules removed unneeded comments in tests removed unneeded comments in tests Change PHPDoc in ResponseHeaderBag::getCookies() to help IDEs [HttpKernel] fix registering IDE links update UPGRADE-4.1 for feature#26332 Form field help option [HttpKernel] Set first trusted proxy as REMOTE_ADDR in InlineFragmentRenderer. [Process] Consider \"executable\" suffixes first on Windows Triggering RememberMe's loginFail() when token cannot be created bumped Symfony version to 4.1.0 updated VERSION for 4.1.0-BETA3 updated CHANGELOG for 4.1.0-BETA3 ...
loru88 commentedJun 19, 2018
Do you think it's possible to have this feature available also in Symfony 3.4? |
xabbuh commentedJun 19, 2018
@loru88 We never add new features in patch versions, but only do that in minor releases. You can read more about our release process athttp://symfony.com/doc/current/contributing/community/releases.html. |



Uh oh!
There was an error while loading.Please reload this page.
Add a form_help method in twig to display a help message in form. A
helpkeyword is added to all FormType to define the message.