terminal42 / contao-conditionalformfields

Display form fields conditionally in Contao Open Source CMS
MIT License
18 stars 13 forks source link

contao-mp_forms + contao-conditionalformfields #74

Closed michaelgawlik closed 1 year ago

michaelgawlik commented 1 year ago

Contao: 4.13.15 PHP: 8.1 contao-mp_forms: 5.0.0 contao-conditionalformfields: 3.0.8

Hi Folks, it's easy to reproduce: just the installation of contao-mp_forms throws an error when you use a simple condition in a fieldset.

Error-Log:

[2023-02-07T11:31:38.603712+01:00] request.INFO: Matched route "tl_page.100". {"route":"tl_page.100","route_parameters":{"_token_check":true,"_controller":"Contao\\FrontendIndex::renderPage","_scope":"frontend","_locale":"de","_format":"html","_canonical_route":"tl_page.100","parameters":"","pageModel":{"Contao\\PageModel":[]},"_route":"tl_page.100","_route_object":{"Contao\\CoreBundle\\Routing\\Page\\PageRoute":[]}},"request_uri":"http://dev.dfw24.de/test","method":"GET"} []
[2023-02-07T11:31:38.617399+01:00] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2023-02-07T11:31:38.676662+01:00] request.CRITICAL: Uncaught PHP Exception Error: "Typed property Terminal42\MultipageFormsBundle\FormManager::$storageIdentifier must not be accessed before initialization" at /htdocs/contao_4_13/vendor/terminal42/contao-mp_forms/src/FormManager.php line 64 {"exception":"[object] (Error(code: 0): Typed property Terminal42\\MultipageFormsBundle\\FormManager::$storageIdentifier must not be accessed before initialization at /htdocs/contao_4_13/vendor/terminal42/contao-mp_forms/src/FormManager.php:64)"} []

Stack Trace:

Error:
Typed property Terminal42\MultipageFormsBundle\FormManager::$storageIdentifier must not be accessed before initialization

  at vendor/terminal42/contao-mp_forms/src/FormManager.php:64
  at Terminal42\MultipageFormsBundle\FormManager->getDataOfAllSteps()
     (vendor/terminal42/contao-conditionalformfields/src/FormHandler.php:166)
  at Terminal42\ConditionalformfieldsBundle\FormHandler->getPreviousDataFromMpForms()
     (vendor/terminal42/contao-conditionalformfields/src/FormHandler.php:151)
  at Terminal42\ConditionalformfieldsBundle\FormHandler->getInput('bedingung')
     (vendor/terminal42/contao-conditionalformfields/src/FormHandler.php:54)
  at Terminal42\ConditionalformfieldsBundle\FormHandler->__construct(object(Form@anonymous/homepages/46/d255659178/htdocs/contao_4_13/vendor/terminal42/contao-mp_forms/src/FormManager.php:273$20b), array('bedingung' => object(FormFieldModel), object(FormFieldModel), object(FormFieldModel), object(FormFieldModel)))
     (vendor/terminal42/contao-conditionalformfields/src/EventListener/FormListener.php:49)
  at Terminal42\ConditionalformfieldsBundle\EventListener\FormListener->onCompileFormFields(array('bedingung' => object(FormFieldModel), object(FormFieldModel), object(FormFieldModel), object(FormFieldModel)), 'auto_form_72', object(Form@anonymous/homepages/46/d255659178/htdocs/contao_4_13/vendor/terminal42/contao-mp_forms/src/FormManager.php:273$20b))
     (vendor/terminal42/contao-mp_forms/src/FormManager.php:359)
  at Terminal42\MultipageFormsBundle\FormManager->loadFormFieldModels()
     (vendor/terminal42/contao-mp_forms/src/FormManager.php:382)
  at Terminal42\MultipageFormsBundle\FormManager->prepare()
     (vendor/terminal42/contao-mp_forms/src/FormManager.php:62)
  at Terminal42\MultipageFormsBundle\FormManager->getDataOfAllSteps()
     (vendor/terminal42/contao-conditionalformfields/src/FormHandler.php:166)
  at Terminal42\ConditionalformfieldsBundle\FormHandler->getPreviousDataFromMpForms()
     (vendor/terminal42/contao-conditionalformfields/src/FormHandler.php:151)
  at Terminal42\ConditionalformfieldsBundle\FormHandler->getInput('bedingung')
     (vendor/terminal42/contao-conditionalformfields/src/FormHandler.php:54)
  at Terminal42\ConditionalformfieldsBundle\FormHandler->__construct(object(Form), array('bedingung' => object(FormFieldModel), object(FormFieldModel), object(FormFieldModel), object(FormFieldModel)))
     (vendor/terminal42/contao-conditionalformfields/src/EventListener/FormListener.php:49)
  at Terminal42\ConditionalformfieldsBundle\EventListener\FormListener->onCompileFormFields(array('bedingung' => object(FormFieldModel), object(FormFieldModel), object(FormFieldModel), object(FormFieldModel)), 'auto_form_72', object(Form))
     (vendor/contao/core-bundle/src/Resources/contao/forms/Form.php:140)
  at Contao\Form->compile()
     (vendor/contao/core-bundle/src/Resources/contao/classes/Hybrid.php:230)
  at Contao\Hybrid->generate()
     (vendor/contao/core-bundle/src/Resources/contao/forms/Form.php:90)
  at Contao\Form->generate()
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php:616)
  at Contao\Controller::getContentElement(object(ContentModel), 'main')
     (vendor/contao/core-bundle/src/Resources/contao/modules/ModuleArticle.php:197)
  at Contao\ModuleArticle->compile()
     (vendor/contao/core-bundle/src/Resources/contao/modules/Module.php:214)
  at Contao\Module->generate()
     (vendor/contao/core-bundle/src/Resources/contao/modules/ModuleArticle.php:70)
  at Contao\ModuleArticle->generate(false)
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php:544)
  at Contao\Controller::getArticle(object(ArticleModel), false, false, 'main')
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php:386)
  at Contao\Controller::getFrontendModule('0', 'main')
     (vendor/contao/core-bundle/src/Resources/contao/pages/PageRegular.php:190)
  at Contao\PageRegular->prepare(object(PageModel))
     (vendor/contao/core-bundle/src/Resources/contao/pages/PageRegular.php:60)
  at Contao\PageRegular->getResponse(object(PageModel), true)
     (vendor/contao/core-bundle/src/Resources/contao/controllers/FrontendIndex.php:320)
  at Contao\FrontendIndex->renderPage(object(PageModel))
     (vendor/symfony/http-kernel/HttpKernel.php:163)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:75)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:202)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:44) 
Toflar commented 1 year ago

I assume this happened because you had no form fields at all yet. Can you check if https://github.com/terminal42/contao-mp_forms/pull/68 fixes your issue (either install that branch or copy the changes in Form Manager - the test you can ignore).

michaelgawlik commented 1 year ago

I installed that branch but it dosn't fix the issue. Also I have form fields.

It's an existing site in Contao 4.9, contao-mp_forms 4.3 and contao-conditionalformfields 2.3 that I rebuilded. When I deinstall mp_forms, the condition works.

I tried this with an existing form an a new one.

FlorinvV commented 1 year ago

I can say, it is a problem not limited to michaelgawlik.

I have got the same problem, also C 4.13.15, mp_forms 5.0.0 & cond_form_fields 3.0.8

[2023-02-14T11:21:59.299858+01:00] request.INFO: Matched route "tl_page.3.root". {"route":"tl_page.3.root","route_parameters":{"_token_check":true,"_controller":"Contao\\FrontendIndex::renderPage","_scope":"frontend","_locale":"de","_format":"html","_canonical_route":"tl_page.3","parameters":"","pageModel":{"Contao\\PageModel":[]},"_route":"tl_page.3.root","_route_object":{"Symfony\\Component\\Routing\\Route":[]}},"request_uri":"https://contaotest.mees-zacke.de/","method":"GET"} []
[2023-02-14T11:21:59.310264+01:00] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2023-02-14T11:21:59.334478+01:00] request.CRITICAL: Uncaught PHP Exception Error: "Typed property Terminal42\MultipageFormsBundle\FormManager::$storageIdentifier must not be accessed before initialization" at /www/htdocs/w0070178/contaotest.mees-zacke.de/vendor/terminal42/contao-mp_forms/src/FormManager.php line 64 {"exception":"[object] (Error(code: 0): Typed property Terminal42\\MultipageFormsBundle\\FormManager::$storageIdentifier must not be accessed before initialization at /www/htdocs/w0070178/contaotest.mees-zacke.de/vendor/terminal42/contao-mp_forms/src/FormManager.php:64)"} []

I tested this with two separate contao installations on two separate servers. The Problem occurs on forms, copied from C 4.9.* as well as completely new created forms

Tested with PHP 8.0 & 8.1

Like with michaelgawlik, the branch doesn't solve this unfortunately

The form I found this was also fully functional in 4.9, containing several pages and conditions, therefore I see no way this occurs because of the lack of form fields

Toflar commented 1 year ago

Actually an issue in conditionalformfields. Should be fixed with https://github.com/terminal42/contao-conditionalformfields/releases/tag/3.0.9.