Problem/Motivation
After upgrading this module from version 4.0.0-alpha5 to 4.0.0-alpha6, I encountered the following issues:
Warning
Warning: Trying to access array offset on value of type null in Drupal\conditional_fields\ConditionalFieldsFormHelper::formFieldGetValues() (line 900 of /var/www/html/public/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php) #0 /var/www/html/public/core/includes/bootstrap.inc(166): _drupal_error_handler_real(2, 'Trying to acces...', '/var/www/html/p...', 900)
#1 /var/www/html/public/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php(900): _drupal_error_handler(2, 'Trying to acces...', '/var/www/html/p...', 900)
#2 /var/www/html/public/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php(830): Drupal\conditional_fields\ConditionalFieldsFormHelper::formFieldGetValues(NULL, Object(Drupal\Core\Form\FormState))
#3 [internal function]: Drupal\conditional_fields\ConditionalFieldsFormHelper::formValidate(Array, Object(Drupal\Core\Form\FormState))
#4 /var/www/html/public/core/lib/Drupal/Core/Form/FormValidator.php(82): call_user_func_array(Array, Array)
#5 /var/www/html/public/core/lib/Drupal/Core/Form/FormValidator.php(274): Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object(Drupal\Core\Form\FormState))
#6 /var/www/html/public/core/lib/Drupal/Core/Form/FormValidator.php(118): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState), 'application_edi...')
#7 /var/www/html/public/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\Core\Form\FormValidator->validateForm('application_edi...', Array, Object(Drupal\Core\Form\FormState))
#8 /var/www/html/public/core/lib/Drupal/Core/Form/FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm('application_edi...', Array, Object(Drupal\Core\Form\FormState))
...
Error
TypeError: Drupal\Component\Utility\NestedArray::getValue(): Argument #2 ($parents) must be of type array, null given, called in /var/www/html/public/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php on line 905 in Drupal\Component\Utility\NestedArray::getValue() (line 69 of /var/www/html/public/core/lib/Drupal/Component/Utility/NestedArray.php).
"/var/www/html/public/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php:905",
"/var/www/html/public/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php:830",
"/var/www/html/public/core/lib/Drupal/Core/Form/FormValidator.php:82",
"/var/www/html/public/core/lib/Drupal/Core/Form/FormValidator.php:274",
"/var/www/html/public/core/lib/Drupal/Core/Form/FormValidator.php:118",
"/var/www/html/public/core/lib/Drupal/Core/Form/FormBuilder.php:593",
"/var/www/html/public/core/lib/Drupal/Core/Form/FormBuilder.php:326",
...
Steps to reproduce
- Install version 4.0.0-alpha5 of conditional_fields.
- Upgrade to version 4.0.0-alpha6.
Comments
Comment #2
franceslui commentedComment #4
nicxvan commentedAre you able to add a test for this?
Comment #5
franceslui commentedI am unable to allocate time to implement a test at the moment. I would greatly appreciate assistance with this, or I can revisit it when my schedule permits. Thank you for your understanding.
Comment #6
joelpittetTargetting against the dev branch instead of the specific version and changing to needs review.
Seems like a regression by accident presumably in #2902164: Controlled-by fields inside a Paragraph don't work
https://git.drupalcode.org/project/conditional_fields/-/commit/962c0a834...
Unfortunately the previous code that worked didn't document why it was needed, nor does the new code document why it's not, so kinda hard to write a test, no?
Comment #8
rnsrk commentedWorks as expected.
Comment #9
jcandan commentedI can also confirm this fixes the error as seemingly introduced by #2902164: Controlled-by fields inside a Paragraph don't work.
Comment #10
odensc+1 - tested and works on our site with complex nested logic + inline entity forms. This fixes the weird regression I described in #2902164-232: Controlled-by fields inside a Paragraph don't work.
Comment #11
nicxvan commentedTest only fails as expected, thanks for the test case!
I also reviewed this and it looks good too.
Comment #12
leducdubleuet commentedWould it be possible please to have a new release including this fix?
Thank you!
Comment #13
dhaval_panara commentedDue to recent updates in the patch https://git.drupalcode.org/project/conditional_fields/-/merge_requests/6... is getting failed to apply on "drupal/conditional_fields": "4.x-dev@dev" version.
Comment #14
dhaval_panara commentedPatch is working till "Merge branch conditional_fields:4.x into 3495402-warning-trying-to" - 42d4ae5ebea9cd077930e6a6cce290edac608822.
URL of the patch : https://git.drupalcode.org/project/conditional_fields/-/commit/047da7b69...
However, it's not working after "fix phpcs issues" commit and with it's hash.
Comment #15
dhaval_panara commentedPatch is working fine after upgrading to the latest dev version.
Comment #18
joelpittetCommitted to 4.x
@franceslui for the report and the fix itself, @rnsrk for the test coverage, @nicxvan for pushing for a test case, and @jcandan and @odensc for confirming it on real sites. This one had been throwing WSODs for people (I see 9 followers) with nested conditional setups since alpha6, so it's good to have it closed out. 🎉
AI disclosure: While doing the MR conflicts most from
40017ea, used AI to to cut the MR back to what 4.x didn't already cover, and to rewrite the unit test to assert behaviour against a realFormStaterather than a mock(my preference). I reviewed the result and verified it with a red (tests-only)/green (tests + fixes). Also, I have been using this patch for ages (scratching an itch)!