I have an integer field that I use to store ISBNs. It worked fine in the past (in Drupal) but trying to add a new node of this type for the first time after upgrading my site to Backdrop, it complains upon trying to save with the message:

"Value must be less than or equal to 1000000" [i.e. 1 million]

When I look at the field config for this content type, it gives a different and much larger max value of 2147483647 (i.e. a bit over 2 billion). 

Looking in the DB, there are many existing 10-digit values as well as quite a few (probably ISBN-13 values) that have been truncated to 2147483647. 

So now I have 2 questions:

1. Obviously 10-digit values are a lot bigger than 1 million, so why is it now insisting that the values must be so small?

2. How can I fix it so that 10 and 13-digit ISBN values can be entered?

Thanks.

Accepted answer

Like yourkshirepudding said, I don't think using a number field is a good idea, because of the limit and leading 0. I would use a text field, and use the module Field Validation to make sure all digits are numerical.

Most helpful answers

@leeksoup, I often use metadata wrappers to assign values to fields attached to entities, so I don't have to worry about the nested array for the field. You need to enable Entity Plus (which you can disable after you are done). And it would look a bit like this.

 

$node_wrapper = entity_metadata_wrapper('node', $node);
$node_wrapper->field_isbn_t = $isbn_t;

That's it. And then you can save the node with $node->save(); . As you can see the metadata wrapper allows you to skip all the array stuff, and you simply assign the value to the field. The wrapper takes care of putting things in the right places.

Comments

Like yourkshirepudding said, I don't think using a number field is a good idea, because of the limit and leading 0. I would use a text field, and use the module Field Validation to make sure all digits are numerical.

@yorkshirepudding, @argiepiano -

Is there a specific API function I should use to save the new short text-field data for those nodes that already have ISBN info? Or just use something like this?

$node->field_isbn_t['und'][0] = ['value' => $isbn_t, 'format' => NULL, 'safe_value' => $isbn_t];

Thanks!

Sorry, not something I have ever done, so I'm not able to advise on this

No problem. I just did some testing, and this is what I ended up figuring out:

$node->field_isbn_t['und'][0] = ['value' => $isbn_t, 'format' => NULL, 'safe_value' => check_plain($isbn_t)];

@leeksoup, I often use metadata wrappers to assign values to fields attached to entities, so I don't have to worry about the nested array for the field. You need to enable Entity Plus (which you can disable after you are done). And it would look a bit like this.

 

$node_wrapper = entity_metadata_wrapper('node', $node);
$node_wrapper->field_isbn_t = $isbn_t;

That's it. And then you can save the node with $node->save(); . As you can see the metadata wrapper allows you to skip all the array stuff, and you simply assign the value to the field. The wrapper takes care of putting things in the right places.

Oh, that is great to know. Thanks!