-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[POC] Add a hook to form_rest for custom field rendering #13412
[POC] Add a hook to form_rest for custom field rendering #13412
Conversation
@@ -320,7 +320,7 @@ | |||
|
|||
{%- block form_end -%} | |||
{%- if not render_rest is defined or render_rest -%} | |||
{{ form_rest(form) }} | |||
{{ form_rest(form, { render_hook: false }) }} |
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 prevents form_rest()
from rendering the hook twice.
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'm wondering maybe we should do the opposite to avoid side effects?
Also if we do it this way, does this mean if you forget to add form_rest
in the form the hook won't be rendered?
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'm wondering maybe we should do the opposite to avoid side effects?
what do you mean by that?
if you forget to add form_rest in the form the hook won't be rendered?
yes
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'm wondering maybe we should do the opposite to avoid side effects?
what do you mean by that?
I meant instead of disabling the feature with the parameter we could use form_rest(form, { render_hook: true })
instead and explicitly enable it so that if we use a simple form_rest(form)
the hook is not rendered
if you forget to add form_rest in the form the hook won't be rendered?
yes
ok, so we will have to modify every existing form to add form_rest
if we want to add the hook?
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.
meant instead of disabling the feature with the parameter we could use form_rest(form, { render_hook: true }) instead and explicitly enable it so that if we use a simple form_rest(form) the hook is not rendered
The idea was to make it render the hook automatically whenever form_rest
is used, but maybe it's smart not render it automatically and control it with a parameter 🤔 IMO one more opinion would be great, ping @matks @sarjon
ok, so we will have to modify every existing form to add form_rest if we want to add the hook?
yes. Also, every form should have a form_rest
already rendered, unless developers missed it (usually by mistake)
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 here seems like form_rest
is called automatically by form_end
So if I understand the current implementation, if you didn't forget to add form_rest
in your form, it will be called one time with the hook (by default) and a second time by form_end (without the hook)
And of course you still have the possibility to prevent the hook in your form with an explicit {{ form_rest(form, { render_hook: false }) }}
This is a bit clearer for me, sorry I wasn't sure about the behavior
It seems to me that this approach is the more user friendly and the less intrusive at the same time, it's a good compromise. But as you said let's confirm it with the others and maybe @eternoendless when he comes bak from holiday (end of the week)
@@ -340,6 +340,10 @@ | |||
{%- endblock form_errors -%} | |||
|
|||
{%- block form_rest -%} | |||
{% if render_hook is not defined or render_hook %} | |||
{{ renderhook('display' ~ name ~ 'FormRest', { form: 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.
there might be a problem with forms that don't have custom names as the hook name will be not unique.
For example, many options forms have "form" as form name.
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.
Indeed this is something we need to change
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.
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.
By the no need to call parent()
or something in this block?
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.
Forget this last comment, I didn't see that children were rendered after
@matks is this PR should go to develop branch? It would be perfect that it would appear in 1.7.6 due to the sample module I am creating would use this hook to demonstrate how forms are being override. Without this I think the sample module will only have the demonstration of overriding the listing only and not the forms since it will not look okey with current implementation. |
What do you mean but "not look OK" ? Inputs really look bad, or just up to PrestaShop UX quality ? This PR would be a lot better in |
@matks I mean they will look like this https://prnt.sc/nc96pk - they look good but they are not aligned with the rest of the content since right now I can't control the html from the hook. I only able to add new form type and the If I recall correctly even the |
Interesting 🤔 but now I'm sure it's really due to our Form Theme (so #11389) rather than Bug bad alignment is not an issue bad enough to make us bend the code freeze rules 😉 . Let's follow Beck's rule : 1) Make it work 2) Make it right 3) Make it fast. Let's finish this PR (with badly aligned inputs) to solve 1) then improve the Form theme to solve 2) . We'll see with eternoendless if a bad form theme is considered a bug for 1.7.6 or not 😉 |
@rokaszygmantas Well it looks promising 👍 actually it's not a POC, this is working right ? @Quetzacoalt91 @jolelievre @eternoendless any feedback on this ? can enable some very interesting customization capabilities for modules |
@matks yeah it's a working POC 😄 |
@jolelievre @PierreRambaud @eternoendless I'd like a 2nd opinion before merge but I really like this idea / PR 😄 |
@matks what's needed for this PR to be merged? besides rebase of course 🙂 |
@matks should I close this PR? 🙂 |
OK, back to this PR now that we have been able to see how #14094 turned out. Also time helps to have a bigger view of the issue. Good news: as @sarjon has started doing, we're going to render form usiong For this PR, here's what we need to check
Waiting for input @rokaszygmantas @sarjon @eternoendless 😄 |
I think whether we need this PR or not depends on decision made here #15130 (comment) 🤔 |
@eternoendless I think if we can render all forms using Question now is: is dispatching a hook into A module that wishes to customize the behavior of a form can already do it by overriding twig template. However this means 2 modules cannot override the same template. But is it a good thing, to allow multiple customization ? Especially now that we have |
I think now, we know the answer is: indeed this PR is now useless. Same customisation capabilities (even better !) will be provided by #16891 |
To test:
Install this module: module
The module will add two new fields in the bottom of language edit form.
Without this PR the fields are unaligned as we cannot control the rendering: https://prnt.sc/nc96pk
With this PR it should look much better, since we can customize the rendering: https://prnt.sc/nc9zjy
This change is