Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form][TwigBridge] Add help_html #29861

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
Jan 25, 2019
Merged

[Form][TwigBridge] Add help_html #29861

merged 1 commit into from
Jan 25, 2019

Conversation

mpiot
Copy link
Contributor

@mpiot mpiot commented Jan 12, 2019

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets no
License MIT
Doc PR symfony/symfony-docs#10978

Sometimes, when we use the form help option, we want to display it as HTML (add bold, italic, a span with a specific class, ...). For security reasons, we escape the help content.

In this PR, I've added an help_html option, seted to false per default. When it set on true, the help content is no longer escaped.

@nicolas-grekas nicolas-grekas added this to the next milestone Jan 24, 2019
@nicolas-grekas
Copy link
Member

Thanks @mpiot, could you please rebase to fix the conflicts? They must be related to the move to short arrays.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

(I just rebased for you)

@nicolas-grekas
Copy link
Member

Thank you @mpiot.

@nicolas-grekas nicolas-grekas merged commit 33f5f85 into symfony:master Jan 25, 2019
nicolas-grekas added a commit that referenced this pull request Jan 25, 2019
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Form][TwigBridge] Add help_html

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | no
| License       | MIT
| Doc PR        | symfony/symfony-docs#...

Sometimes, when we use the form `help` option, we want to display it as HTML (add bold, italic, a span with a specific class, ...). For security reasons, we escape the `help` content.

In this PR, I've added an `help_html` option, seted to false per default. When it set on true, the `help` content is no longer escaped.

Commits
-------

33f5f85 [Form][TwigBridge] Add help_html option
@mpiot
Copy link
Contributor Author

mpiot commented Jan 25, 2019

Thanks a lot :-) I was thinking about doing this tonight, it's faster like this :D

@mpiot mpiot deleted the help-html branch January 25, 2019 16:54
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Feb 11, 2019
This PR was merged into the master branch.

Discussion
----------

[FormType] Add help_html documentation

Add documentation about the new feature symfony/symfony#29861

Commits
-------

cc6a5f3 Add help_html
@plandolt
Copy link
Contributor

I wonder if we should also add a boolean option label_html with a similar functionality like the newly help_html? Would it be appreciated if one would create a PR for that? An old issue (#8733) suggested that but was closed due to lack of traction.

@mpiot
Copy link
Contributor Author

mpiot commented Feb 20, 2019

@scuben I can do that, (I've hesitate to do that when I've done this PR), but is it really usefull ?
In which case we need to implement HTML in a label ? Often the label is stilized by it class and we don't really need to use HTML tags.

@plandolt
Copy link
Contributor

@mpiot I just had a use case to add a TOS link to the label of a checkbox and would have loved this feature 👍

@mpiot
Copy link
Contributor Author

mpiot commented Feb 20, 2019

@scuben Okay, I see, then it should be implement in CheckboxType, RadioType, and ChoiceType only ?

@plandolt
Copy link
Contributor

I would implement it in any type which would reduce complexity as you know you can relay on that it's available in any label.

@mpiot
Copy link
Contributor Author

mpiot commented Feb 20, 2019

It's comprehensive, then it's easier to implement too. I start it, when I've some times :-)

@xabbuh
Copy link
Member

xabbuh commented Feb 20, 2019

I think it would be better to discuss this in a new issue before investing time in something that might not be merged. Personally, I don't see this as a common use case and would rather suggest to use a custom form theme for cases when you really need this instead.

@mpiot
Copy link
Contributor Author

mpiot commented Feb 20, 2019

Okay, then @scuben, can you create an Issue ? You can refer it and ping me, if there are a real interest from users, I'll do it.

For the moment, I've must do that one times, and I've used a custom form theme thath extends which theme I use, with a custom type.

nicolas-grekas added a commit that referenced this pull request Mar 12, 2020
This PR was squashed before being merged into the 5.1-dev branch.

Discussion
----------

[Form] Add label_html attribute

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT
| Doc PR        | symfony/symfony-docs#13316

I propose to add a new attribute to `BaseType` class so it is easy to include html tags in labels for, both, buttons and other elements that inherit from `FormType` class. This gives you an ability to add, e.g. a glyphicon to a button, or a link to a checkbox, simply inside the `FormBuilder`, which means you can just do
```twig
{{ form(form) }}
```
inside a template.

**Sidenotes**
1. I have started working on this two days ago and it the meantime @alexander-schranz made a similar proposition in #31358. If necessary, I can close my PR and @alexander-schranz can include my suggestions inside his PR.
1. I have just read in #29861 that @mpiot wanted to include this idea in his PR. With respect to @xabbuh's comments from that PR, I hope that my PR will be at least a good place to discuss, if the proposed feature is a good solution.

Commits
-------

239fe04 [Form] Add label_html attribute
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