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

Skip to content

[Form] Add label_raw attribute to form theme #31358

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

alexander-schranz
Copy link
Contributor

@alexander-schranz alexander-schranz commented May 2, 2019

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

There are some usecases where you want to render a label as raw (e.g. checkbox with a link in it). This change should make it easier todo this without copying the whole form_label block logic.

Example:

{% block _my_label %}
    {%- set label_raw = true -%}
    {{- block('form_label') -}}
{% endblock %}

Should we add this also to the FormExtension as attribute? Or is it a theming only thing like #30320.

@alexander-schranz alexander-schranz changed the title Add label_raw attribute to form theme [Form] Add label_raw attribute to form theme May 2, 2019
@alexander-schranz alexander-schranz force-pushed the feature/easier-label-raw branch from 7cae00f to 1170b70 Compare May 2, 2019 07:51
@Simperfit
Copy link
Contributor

Could you please prepare a doc PR ?

@alexander-schranz
Copy link
Contributor Author

alexander-schranz commented May 2, 2019

Should we add the label_raw attribute also to the BaseType? So it can also be controlled from PHP? As I think it always depends on the used translation key which is also be configured in PHP.

@xabbuh
Copy link
Member

xabbuh commented May 4, 2019

I am not convinced that this is a common enough use case to have it as part of the core form themes.

@xabbuh
Copy link
Member

xabbuh commented May 4, 2019

But maybe I am wrong with that assumption. See #31375 for another approach which tackles the same use case.

@przemyslaw-bogusz
Copy link
Contributor

In my opinion, HTML inside a label is quite common, e.g. bolded text for part of a label, link in a checkbox used for accepting some terms or regulations, icons on a button. I would recommend adding this option, same as was done with help. There should be a way to add HTML, without having to do much tweaking inside Twig.

@alexander-schranz
Copy link
Contributor Author

Yeah think this would make some things easier. The usecase I have mostly in all forms is the data privacy protection checkbox with a tag link in it. As there is something like help_html I think its totally make sense to have also label_html in it.

I will close this PR in favor of @przemyslaw-bogusz #31375 PR

@alexander-schranz alexander-schranz deleted the feature/easier-label-raw branch May 9, 2019 16:57
@przemyslaw-bogusz
Copy link
Contributor

@alexander-schranz Thank you very much for the support!

@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
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