Array flip error when a taxonomy term field has a NULL value

Created on 6 March 2012, almost 13 years ago
Updated 26 May 2023, over 1 year ago

Problem/Motivation

If a field associated with an entity points to a taxonomy term, and there happens to be no data in that field on that entity (i.e., the term tid is NULL), then taxonomy_field_formatter_prepare_view() attempts to load taxonomy term data for a NULL tid. In doing so, DrupalDefaultEntityController::load() attempts to array flip a NULL value, which is not allowed (only strings/ints are allowed), resulting in the following PHP warning and associated log message:

Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 177 of /path/to/drupal/includes/entity.inc).

Proposed resolution

The proposed resolution is a simple patch that performs a check for is_numeric() on the tid in taxonomy_field_formatter_prepare_view() before adding it to the list of tids to be loaded. The rationale here is that taxonomy_term_load() does the same check before calling taxonomy_term_load_multiple(), so we should be performing the same check in taxonomy_field_formatter_prepare_view().

Remaining tasks

  • The proposed patch should get at least a couple of non-bot reviews before committing. It's relatively small though, and passes tests.
  • Afterward, the patch will need to be applied to Drupal 7 as well.

User interface changes

None.

API changes

None.

Original report by POVYLAZZZ

I was working on my site then on node creation pages I started seeing this error:
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /var/www/p/includes/entity.inc).
What could have caused it?
I read that FileField Sources and Page titles could be the reason of this error but I have never used the first and have not yet installed Page titles.
What type of module could be to blame?

πŸ› Bug report
Status

Fixed

Version

7.0 ⚰️

Component
TaxonomyΒ  β†’

Last updated 23 minutes ago

  • Maintained by
  • πŸ‡ΊπŸ‡ΈUnited States @xjm
  • πŸ‡¬πŸ‡§United Kingdom @catch
Created by

πŸ‡±πŸ‡ΉLithuania POVYLAZZZ

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024