Problem/Motivation
Since upgrading to PHP8, InlineEntityForm::extractFormValues() can trigger a warning when there is no form element for one of the items. I'm not entirely sure how that happens, it might be access control, it might be that the item has been removed from the form. This is a problem, because now any FunctionalTest that uses an inline entity form, where you don't set the value of the field counts as a failure.
PHPUnit 9.5.13 by Sebastian Bergmann and contributors.
Warning: Your XML configuration validates against a deprecated schema.
Suggestion: Migrate your XML configuration using "--migrate-configuration"!
Testing Drupal\Tests\ck_contacts\Functional\ContactAddTypeInterfaceTest
E 1 / 1 (100%)
Time: 00:13.500, Memory: 6.00 MB
There was 1 error:
1) Drupal\Tests\ck_contacts\Functional\ContactAddTypeInterfaceTest::testAddTestAttorneyRoleToIndividual
Exception: Warning: Trying to access array offset on value of type null
Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormSimple->extractFormValues()() (Line: 140)
/var/www/html/web/core/lib/Drupal/Core/Test/HttpClientMiddleware/TestHttpClientMiddleware.php:49
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:204
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:153
/var/www/html/vendor/guzzlehttp/promises/src/TaskQueue.php:48
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:248
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:224
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:269
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:226
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:62
/var/www/html/vendor/guzzlehttp/guzzle/src/Client.php:182
/var/www/html/web/core/tests/Drupal/Tests/DrupalTestBrowser.php:137
/var/www/html/vendor/symfony/browser-kit/Client.php:404
/var/www/html/vendor/symfony/browser-kit/Client.php:324
/var/www/html/vendor/friends-of-behat/mink-browserkit-driver/src/BrowserKitDriver.php:719
/var/www/html/vendor/friends-of-behat/mink-browserkit-driver/src/BrowserKitDriver.php:494
/var/www/html/vendor/behat/mink/src/Element/NodeElement.php:153
/var/www/html/vendor/behat/mink/src/Element/NodeElement.php:161
/var/www/html/vendor/behat/mink/src/Element/TraversableElement.php:115
/var/www/html/web/modules/custom/contacts/tests/src/Functional/ContactAddTypeInterfaceTest.php:69
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:726
ERRORS!
Tests: 1, Assertions: 14, Errors: 1.
Remaining self deprecation notices (31)
Remaining direct deprecation notices (1)
Other deprecation notices (2)The code causing the warning is here:
foreach ($items as $delta => $value) {
$element = NestedArray::getValue($form, [$field_name, 'widget', $delta]);
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $element['inline_entity_form']['#entity'];
$weight = isset($submitted_values[$delta]['_weight']) ? $submitted_values[$delta]['_weight'] : 0;
$values[$weight] = ['entity' => $entity];
}
Proposed resolution
Check whether element exists on line 138 before trying to access its properties.
Issue fork inline_entity_form-3261999
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
rlmumfordConfirmed that PHP made what used to be a notice a warning:
https://www.php.net/manual/en/migration80.incompatible.php
Comment #4
rlmumfordComment #5
andrei.vesterliHello @rlmumford
Who can merge the opened MR? I've checked it myself and it's workable.
Regards,
Andrei
Comment #6
geek-merlinThanks @rlmumford for spotting and fixing this! LGTM.
Comment #7
geek-merlinComment #8
geek-merlinHuh, why do i get a merge error now an can not merge?
Comment #9
andrei.vesterliHello @geek-merlin
It looks like: Merge blocked: merge conflicts must be resolved. Users who can write to the source or target branches can resolve the conflicts.
so, some conflicts...
Hey @rlmumford
Can you do something with that?
Comment #10
avpadernoComment #11
rlmumford@geek-merlin thanks for updating that. Is there a way I can make my fork more public?
Comment #12
geek-merlinAh yes. I found the rebase button in gitlab, and we're green...
Comment #14
geek-merlinThanky ya all! 🥳 Merged.
Will roll a new release after some days collecting up other stuff.