Warning: array_flip(): Can only flip string and integer values

Created on 22 May 2023, over 1 year ago
Updated 25 May 2023, over 1 year ago

Problem/Motivation

PHP warning is thrown when saving poll on PHP 8.1+:

Warning: array_flip(): Can only flip string and integer values, entry skipped in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 312 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).
Drupal\Core\Entity\EntityStorageBase->loadMultiple(Array) (Line: 418)
Drupal\poll\Entity\Poll->preSave(Object) (Line: 562)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 756)
Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object) (Line: 517)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 804)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)
Drupal\Core\Entity\EntityBase->save() (Line: 74)
Drupal\poll\Form\PollForm->save(Array, Object)

Steps to reproduce

  1. Install Drupal with PHP 8.1+
  2. Create a new poll with a few choices
  3. Edit the poll and save

Issue occurs because the removed choices detection does not consider the blank new choice.

Proposed resolution

Wrap array_diff($original_choices, $current_choices) with array_filter to remove blank new choice.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇺🇸United States robphillips

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

Comments & Activities

Production build 0.71.5 2024