This issue was originally found and reported for D7. See https://drupal.org/node/2044135

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.

Comments

lliss’s picture

Status: Active » Needs review
StatusFileSize
new933 bytes

This patch should resolve this issue.

prashant.c’s picture

s_gupta_14’s picture

I am getting an error message
"This value should be of the correct primitive type."
when i try to save my integer field value. Even after applying this patch

prashant.c’s picture

Issue summary: View changes
Status: Needs review » Needs work

#3 is right. I am also getting the same error while saving.

sidharthap’s picture

same here , i am also facing same error while saving the node.

swentel’s picture

Issue tags: +Needs tests

We'll need tests for this.

swentel’s picture

+++ b/core/modules/options/options.module
@@ -190,6 +190,15 @@ function options_field_settings_form_validate_allowed_values($element, &$form_st
+      // PHP is kind of stupid about typecasting. We've passed other validation

No need to use the word 'stupid' in comments :)

lliss’s picture

Re comment #3. I'm running off the latest version the 8.x branch as of 2013-Nov-22 and I'm not getting that error when I save a node or when I save the field. So I'm not sure that your issue is realated. I'm running php 5.3.10.

The error you've described comes from
core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/PrimitiveTypeConstraint.php

In reference to Comment #7 I've attached another patch with less snark.

lliss’s picture

StatusFileSize
new927 bytes
marthinal’s picture

The last submitted patch, 1: drupal-integer-list-2047733-1.patch, failed testing.

lliss’s picture

lliss’s picture

lliss’s picture

StatusFileSize
new940 bytes
lliss’s picture

Status: Needs work » Needs review

The last submitted patch, 9: drupal-integer-list-2047733-8.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 14: drupal-integer-list-2047733-14.patch, failed testing.

The last submitted patch, 14: drupal-integer-list-2047733-14.patch, failed testing.

marthinal’s picture

Status: Needs work » Needs review
marthinal’s picture

Status: Needs review » Needs work

And now Needs Test.

marthinal’s picture

Status: Needs work » Needs review
StatusFileSize
new1.41 KB
new2.33 KB

Let's take a look at the results.

marthinal’s picture

Looks like the status of the patch is cached or not updated so I try again.

The last submitted patch, 21: drupal-integer-list-2047733-test-should-fail.patch, failed testing.

The last submitted patch, 21: drupal-integer-list-2047733-21.patch, failed testing.

The last submitted patch, 22: drupal-integer-list-2047733-test-should-fail.patch, failed testing.

larowlan’s picture

Can you expand the comment in the fix further detailing inputs and outputs ie with this in, you get this out, with something else in, you get something else out?
The code needs to be read a few times to understand what its doing, so a bigger comment will help

marthinal’s picture

@larowlan sure.

Let me know if this is ok.

Many thanks.

larowlan’s picture

Sorry, not in the actual test, but in the changes to the field storage.

marthinal’s picture

Upss ok I see. New comment added.

Status: Needs review » Needs work

The last submitted patch, 29: drupal_integer_list_with_test-2047733-29.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Version: 8.9.x-dev » 9.3.x-dev
Status: Needs work » Closed (cannot reproduce)

I tested this on Drupal 9.3.x, standard install. I followed the steps given in the IS. The saved node shows the value and when re-editing the value is also shown. The key is stored in the db as an integer.

Therefore, closing as outdated. If this is incorrect reopen the issue, by setting the status to 'Active', and add a comment explaining what still needs to be done.

Thanks!