Install
Works with Drupal: ^9.4 || ^10Using Composer to manage Drupal site dependencies
Alternative installation files
Download tar.gz
636.28 KB
MD5: e2003e6ee3ee5b7df21ff68c87fec3cf
SHA-1: 777ed67a73f632fbc6b98e362b2f4bf7afa20c10
SHA-256: d165e4d8aba74205f69eedb21bbba5578dbedf67cdab97c535f6c211e8418de3
Download zip
650.04 KB
MD5: d48f75262fbb2ade5c4ebab62b91e5f7
SHA-1: 76f4df68caf22f81ffd4f76a7500a52225015058
SHA-256: be8eae5b8f7cf4f08ec2dbb56820f5347631c1e5a00e3e191fec4f6e809f8057
Release notes
Fixed:
#3385921: xnumber leads to PHP fatal errors in unrelated modules
Starting from this release saving xnumber value programmatically will go through the same validation process as saving it from the UI. An attempt to save a wrong value will result in a fatal error. It is recommended to explicitly set min on a field config settings page and check validity of the value in your code like the following:
// The BCMath requires string number arguments.
$value = \Drupal\xnumber\Utility\Xnumber::toString(12345.56789);
$settings = $my_entity->get('field_my_xnumber')->getFieldDefinition()->getSettings();
$step = is_numeric($settings['step']) ? $settings['step'] : NULL;
$step_scale = $step ? \Drupal\xnumber\Utility\Xnumber::getDecimalDigits($step) : 0;
$min = is_numeric($settings['min']) ? $settings['min'] : NULL;
// If max is not set any string number might be used here.
$max = is_numeric($settings['max']) ? $settings['max'] : '123456789';
if ($is_valid = bccomp($value, $max, $step_scale) <= 0) {
$is_valid = $min ? bccomp($value, $min, $step_scale) >= 0 : $is_valid;
if ($is_valid && $step) {
$is_valid = \Drupal\xnumber\Utility\Xnumber::validStep($value, $step, $min);
}
}
if ($is_valid) {
$my_entity->set('field_my_xnumber', $value)->save();
}
else {
// Do something ...
}
The previous release notes also apply to the current one: