core
core copied to clipboard
Move getForm hook into the form hybrid.
As stated here #7660 the getForm
hook is only triggered then using Controller::getForm
and not when a form content element is rendered. I suggest to move the hook into the Form
class to fix this issue.
There are also hooks in the Controller::getFrontendModule()
and Controller::getContentElement()
methods, which are not triggered in the generate()
methods of the corresponding classes. Therefore I am against merging this.
The difference is that for the regular use case (using content element in an article) the getContentElement
method is triggered. Same for frontend modules in the regular page.
https://github.com/contao/core/blob/9ca7b0d03b522622ce4bd2b00ad4fc34efbf28f6/system/modules/core/modules/ModuleArticle.php#L213 https://github.com/contao/core/blob/9ca7b0d03b522622ce4bd2b00ad4fc34efbf28f6/system/modules/core/pages/PageRegular.php#L133-L137
So the hooks are called in the default way Contao works. Only the getForm hooks is only triggered when a form is used as insert tag or a third party extension calls Controller::getForm
.
But in these cases, the getContentElement
or getFrontendModule
hooks are triggered. Then the getForm
hook would be triggered additionally, wouldn't it?
But in these cases, the getContentElement or getFrontendModule hooks are triggered. Then the getForm hook would be triggered additionally, wouldn't it?
Sorry, missed that question up to now.
No, that's not the case. Because than the hybrid class is instantiated and not the Controller::getForm
is called.
Moving the hook would be a BC break because it might not be expected that the hook is called for every form.
We would have to add an additional hook and I don’t know if we want that either.
Controller::getForm()
works as a factory here so the issue is rather that the content element is not using getForm()
. This should be the fix, imho.
You should probably use the existing hooks for getContentElement and getFrontendModule instead and check there if the element is a form.
Moving the hook would be a BC break because it might not be expected that the hook is called for every form.
Also it might not be expected that the hook is not called. The docs claims it allows to manipulate the generated form: https://docs.contao.org/books/api/extensions/hooks/getForm.html#getform
Controller::getForm() works as a factory here so the issue is rather that the content element is not using getForm(). This should be the fix, imho.
Would be fine with me.
You should probably use the existing hooks for getContentElement and getFrontendModule instead and check there if the element is a form.
That's what I ended up doing here. But still think, it's wrong. :D
Would be fine with me.
Could you update the PR accordingly then? That should fix the issue, right?
Would be fine with me.
Could you update the PR accordingly then? That should fix the issue, right?
Hm, had a look in the code again. My answer was false. It would end in an recursive loop as Controller::getForm
instantiates the Form
hybrid. If Form::generate
calls Controller::getForm
your webserver will be happy. :)
@dmolineus If you still need this, please create the PR again at https://github.com/contao/contao.