-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
form_row block override in form theme does not work for checkbox #515
Comments
It turns out this is due to the fact that more specific block overrides are used from Is there a way to tell Symfony forms not to use globally defined themes, but only those specified in theme template? |
I'd say it's not possible, but let's ask to a real Symfony Forms expert: @HeahDude could you confirm or deny this? Thanks! |
Hello @emodric, you need to override the template when you don't want to use a global one, see http://symfony.com/doc/current/form/form_customization.html#referencing-blocks-from-inside-the-same-template-as-the-form for an example of "picking" some specific blocks from a template. |
@HeahDude Yes, I'm aware of that, but it would be quite useful to specify in Our usecase is an administration interface for a layout management application built on top of Symfony framework, It can be installed and used on many full stack Symfony apps like eZ Platform, Sylius and even this Symfony Demo app. We have a form theme that skins many forms in the administration interface and we extended from We fixed it by overriding the blocks ourselves, but the issue is that we cannot control what themes may be activated globally. Therefore, to build the administration interfaces that are visually completely different from the rest of the app, I think it would be good to have an option to disable usage of global themes per form. |
@emodric I think the easiest would then to maintain your own template files, because you can't control that actually, and those framework files may evolve in the future and potentially break your app. |
@HeahDude Yes, sure, but that's a separate issue. Because, even if we maintain our separate files, we would need to define EVERY possible block in our form theme to stop the globally defined themes from interfering. A simple example: If I want my admin interface to have a sepecific design for every form row, I would define a However, if a globally defined theme specifies an override for a specific row, for example |
This is a feature that should be added in symfony core.
Indeed, but sadly there is no other way for now. |
Yes, that is my point ;) My idea would be to add an
If that sounds good, maybe I could work on it to create a PR? |
|
@HeahDude PR created at symfony/symfony#22610 |
Let's close this issue because it's not actionable for the Symfony Demo app. Thanks! |
…efault themes when rendering a form (emodric) This PR was merged into the 3.4 branch. Discussion ---------- [Form] [TwigBridge] Added option to disable usage of default themes when rendering a form | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | symfony/symfony-docs#8495 This adds a possibility to use `only` keyword in `form_theme` tag to disable usage of globally defined form themes, e.g. `{% form_theme form with ['common.html.twig', 'form/fields.html.twig'] only %}` Otherwise, in order to completely control the rendering of the forms (for example in custom admin interfaces), one would need to use a form theme which has all the possible twig blocks defined to prevent globally defined themes to interfere with the rendering. `only` keyword is already used when including a Twig template to transfer only the variables which are explicitly defined in the `include` tag, so it seemed natural to use it here too. This, of course, means that the user will need to manually `use` all of the templates that are required to render the form, including `form_div_layout.html.twig` This issue is described in details over at Symfony Demo repo: symfony/demo#515 TODO: - [x] submit changes to the documentation Commits ------- e0681f9 [Form] [TwigBridge] Added option to disable usage of default themes when rendering a form
I tried adding an override for
form_row
block inapp/Resources/views/form/layout.html.twig
:I also added a boolean property to one of the entities (for example Post), and corresponding checkbox field to PostType.
It turns out that
form_row
block override is not applied to Checkbox form type, and I couldn't find the reason why.This is not an issue in Symfony nor an issue with version of PHP. I tested on PHP 5.6, PHP 7.1 and both show this behaviour. I also tested on Sylius (with Symfony 3.2) and it works okay there, so I think it is related to something in this demo.
If this is intended, how do I make the checkbox form type use my
form_row
override?Thanks!
The text was updated successfully, but these errors were encountered: