When creating an integer list field,
if you manually add keys that have leading zeros,
then the keys get stored as strings and the data is not properly displayed.

The saved values on the content that are stored in the database are fine however.

To reproduce:

  1. Add a new integer list field to a content type
  2. Manually add keys for example
    01|Jan
    02|Feb
    03|March
    
  3. Save the field and note that there are no validation errors.
  4. Create a new piece of content and fill in a value for this field.
  5. View the content and note that the key is displayed but not the value.
  6. Edit the content and note that the proper value is not automatically set.

This is due to the fact that the leading zero passes is_numeric validation and passes a regex checking to ensure that all characters are numeric. But PHP typecasts this as a string. We can simply fix this with the patch attached in the comment.

CommentFileSizeAuthor
#1 drupal-integer-list-2044135-1.patch936 byteslliss

Comments

lliss’s picture

StatusFileSize
new936 bytes

Patch attached

lliss’s picture

Issue summary: View changes

fix a typo

lliss’s picture

Title: integer list fields store keys as strings if there are leading zeros » integer list fields store keys as strings if there are leading zeros - backport

This is now a drupal 8 issue. (https://drupal.org/node/2047733).

stephen Piscura’s picture

Hey lliss,

Thanks for your work on the patch. I applied it to Drupal 7.21 and am still experiencing the error. Could this be because i'm two releases behind? Or am i missing something else obvious?

stephen Piscura’s picture

Sorry, a bit more info:

All six steps you specified in the original issue are still happening.

Plus this error, which may or may not be related:
Notice: Array to string conversion in DrupalDefaultEntityController->cacheGet() (line 369 of /includes/entity.inc).

lliss’s picture

This patch doesn't fix the existing data.

stephen Piscura’s picture

Thank you! Just rebuilt the field and it's working like a charm!

stephen Piscura’s picture

Issue summary: View changes

add numbered list.

swentel’s picture

Issue summary: View changes
Status: Needs review » Closed (duplicate)

One issue is enough - needs to be fixed in D8 first.

#2047733: integer list fields store keys as strings if there are leading zeros