Warning: Undefined array key "weight" in Entity

Created on 21 October 2024, 2 months ago

After updating PHP from 7.4 to 8.1 on a Drupal 9.5.11 site, we started encountering warnings on the /user page. The warnings point to an undefined array key 'weight' in the EntityViewBuilder->buildMultiple() and EntityViewDisplay->buildMultiple() methods. These warnings did not appear under PHP 7.4 and seem to be related to PHP 8.1's stricter handling of undefined array keys.

  • Drupal Version: 9.5.11
  • PHP Version: 8.1 (after upgrade from 7.4)
  • Modules: List any additional contributed/custom modules if applicable.
  • Warning: Undefined array key "weight" in Drupal\Core\Entity\EntityViewBuilder->buildMultiple() (line 300 of /var/www/flex temp/docroot/core/lib/Drupal/Core/Entity/EntityViewBuilder.php).
  • Warning: Undefined array key "weight" in Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple() (line 276 of /var/www/flex temp/docroot/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php).

Steps to reproduce:

  • Upgrade PHP from 7.4 to 8.1.
  • Access the /user page on the Drupal site.
  • Observe the warnings in the logs or on the page.
🐛 Bug report
Status

Active

Version

9.5

Component

entity system

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024