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:
- Add a new integer list field to a content type
- Manually add keys for example
01|Jan
02|Feb
03|March
- Save the field and note that there are no validation errors.
- Create a new piece of content and fill in a value for this field.
- View the content and note that the key is displayed but not the value.
- 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
Comment #1
lliss commentedThis patch should resolve this issue.
Comment #2
prashant.c1: drupal-integer-list-2047733-1.patch queued for re-testing.
Comment #3
s_gupta_14 commentedI 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
Comment #4
prashant.c#3 is right. I am also getting the same error while saving.
Comment #5
sidharthapsame here , i am also facing same error while saving the node.
Comment #6
swentel commentedWe'll need tests for this.
Comment #7
swentel commentedNo need to use the word 'stupid' in comments :)
Comment #8
lliss commentedRe 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.
Comment #9
lliss commentedComment #10
marthinal commented1: drupal-integer-list-2047733-1.patch queued for re-testing.
Comment #12
lliss commentedComment #13
lliss commentedComment #14
lliss commentedComment #15
lliss commentedComment #19
marthinal commented14: drupal-integer-list-2047733-14.patch queued for re-testing.
Comment #20
marthinal commentedAnd now Needs Test.
Comment #21
marthinal commentedLet's take a look at the results.
Comment #22
marthinal commentedLooks like the status of the patch is cached or not updated so I try again.
Comment #26
larowlanCan 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
Comment #27
marthinal commented@larowlan sure.
Let me know if this is ok.
Many thanks.
Comment #28
larowlanSorry, not in the actual test, but in the changes to the field storage.
Comment #29
marthinal commentedUpss ok I see. New comment added.
Comment #40
quietone commentedI 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!