-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form][TwigBridge] Add row_attr to form theme #30320
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
I like the idea 👍 |
6460b8a
to
2d59e26
Compare
I am not sure if this is a common enough use case or if it's enough to let users add this in their own form type extensions. |
@xabbuh it would make it easer to create reusable themes. Currently you need to check if the installed symfony version has a Another fix to this issue could be adding a new block to the form_div_layout:
|
I would not be in favor of adding yet a new option for the view level unless we can workaround another way. I think we could just change that line https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig#L324 to set it only when it's not done before, that would allow you to reset only that value in your block. WDYT? |
I have an equivalent of this option (I named it I vote 👍 for adding this in core. |
I don't get why this should be an option? you just need to pass it as context in {{ form(some_form, { widget_attr: ... }) }} ? |
@HeahDude but |
Yes but we can do both if we add |
@HeahDude now I get you. For me ok just add it to the theme and not to the FormType. What do the others think? /cc @stof @OskarStark |
@HeahDude's suggestion sounds better to me than adding another option for this. |
To add an argument on this, ppl wanting an option can still rely on form type extension, and define their own targets which may not be FormType. |
Thank you @alexander-schranz. |
…er-schranz) This PR was squashed before being merged into the 4.3-dev branch (closes #30320). Discussion ---------- [Form][TwigBridge] Add row_attr to form theme | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | waiting for confirmation to implement | Fixed tickets | | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Currently you need to copy the whole form_row block if you just want to add a class to the form_row div. Instead we could introduce a `row_attr` which can then simple be set the following in the theme e.g.: ```twig {% block form_row %} {% set row_attr = { class: 'form__field' } %} {{ parent() }} {% endblock %} ``` or in php: ``` $builder->add('test', TextType::class, ['row_attr' => ['class' => 'form__field']]); ``` Commits ------- 7ab1b00 [Form][TwigBridge] Add row_attr to form theme
Could you add this to the bootstrap form themes, too? Currently only the form_div_layout features the |
Also this is not working out of the box, option has to be defined first: $builder->add('test', TextType::class, ['row_attr' => ['class' => 'form__field']]); |
Currently you need to copy the whole form_row block if you just want to add a class to the form_row div. Instead we could introduce a
row_attr
which can then simple be set the following in the theme e.g.:or in php: