core icon indicating copy to clipboard operation
core copied to clipboard

Move getForm hook into the form hybrid.

Open dmolineus opened this issue 8 years ago • 10 comments

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.

dmolineus avatar Oct 17 '16 18:10 dmolineus

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.

leofeyer avatar Oct 17 '16 18:10 leofeyer

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.

dmolineus avatar Oct 17 '16 19:10 dmolineus

But in these cases, the getContentElement or getFrontendModule hooks are triggered. Then the getForm hook would be triggered additionally, wouldn't it?

leofeyer avatar Jan 19 '17 15:01 leofeyer

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.

dmolineus avatar Jan 15 '18 15:01 dmolineus

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.

ausi avatar Oct 18 '18 13:10 ausi

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.

Toflar avatar Oct 18 '18 13:10 Toflar

You should probably use the existing hooks for getContentElement and getFrontendModule instead and check there if the element is a form.

ausi avatar Oct 18 '18 13:10 ausi

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

dmolineus avatar Oct 18 '18 14:10 dmolineus

Would be fine with me.

Could you update the PR accordingly then? That should fix the issue, right?

Toflar avatar Oct 18 '18 14:10 Toflar

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 avatar Oct 18 '18 15:10 dmolineus

@dmolineus If you still need this, please create the PR again at https://github.com/contao/contao.

leofeyer avatar Oct 17 '22 15:10 leofeyer