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.

Command icon 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

rlmumford created an issue. See original summary.

rlmumford’s picture

Confirmed that PHP made what used to be a notice a warning:

https://www.php.net/manual/en/migration80.incompatible.php

rlmumford’s picture

Status: Needs work » Needs review
andrei.vesterli’s picture

Hello @rlmumford

Who can merge the opened MR? I've checked it myself and it's workable.

Regards,
Andrei

geek-merlin’s picture

Thanks @rlmumford for spotting and fixing this! LGTM.

geek-merlin’s picture

Status: Needs review » Reviewed & tested by the community
geek-merlin’s picture

Version: 8.x-1.0-rc9 » 8.x-1.x-dev
Status: Reviewed & tested by the community » Needs work

Huh, why do i get a merge error now an can not merge?

andrei.vesterli’s picture

Hello @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?

avpaderno’s picture

Issue tags: -PHP8 +PHP 8.0
rlmumford’s picture

Status: Needs work » Reviewed & tested by the community

@geek-merlin thanks for updating that. Is there a way I can make my fork more public?

geek-merlin’s picture

Ah yes. I found the rebase button in gitlab, and we're green...

geek-merlin’s picture

Status: Reviewed & tested by the community » Fixed

Thanky ya all! 🥳 Merged.
Will roll a new release after some days collecting up other stuff.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.