For example search_api_clir creates a standard number form element:
https://git.drupalcode.org/project/search_api_clir/-/blob/2abc3de46aa653...
$form['third_party_settings']['search_api_clir']['cron']['limit'] = [
'#type' => 'number',
'#min' => 0,
'#title' => t('Limit'),
'#description' => t('Number of translations to be requested per cron run. Setting it to "0" will disable the cron job.'),
'#default_value' => $settings['cron']['limit'],
];
By simply installing xnumber it hijacks the validation of form elements and causes a fatal error:
TypeError: bcscale(): Argument #1 ($scale) must be of type ?int, float given in bcscale() (line 39 of modules/contrib/xnumber/src/Utility/Xnumber.php).
Drupal\xnumber\Utility\Xnumber::validStep('0.5', 0.1, 0) (Line: 56)
Drupal\xnumber\Render\Element\Xnumber::validateNumber(Array, Object, Array)
call_user_func_array(Array, Array) (Line: 282)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'search_api_index_edit_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('search_api_index_edit_form', Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('search_api_index_edit_form', Array, Object) (Line: 325)
Comments
Comment #2
mkalkbrennerI just checked the schema of search_api_clir. It is correct:
Comment #3
mkalkbrennerI did some more debugging and it turned out that the field in question isn't
limitbutslopwhich belongs to search_api_solr:The issue seems to be caused by the recent changes to
XNumber::getDecimalDigits()which gets called with float 0.5 in this case:https://git.drupalcode.org/project/xnumber/-/commit/b3c60cfe763bcd65e631...
Comment #4
drugan commentedThanks for reporting.
The reason is that xnumber whenever possible relies on string numbers which actually you get while using a number form widget in the UI.
I've fixed it and now trying to add more tests for saving non-string numbers programmatically on entity field.
Comment #6
drugan commented@mkalkbrenner
I created custom valid step and min and max constraint validators. So now saving
xnumbervalue programmatically works the same as doing it from the UI.Also, I added to the
XnumberFieldTesta few lines to save an integer or float (non-string) value on entity xnumber field.Please check it in your environment and if it's okay I will create 2.0.0-beta2 release.
Comment #7
drugan commentedAdjusted the
runRandomNumberDecimalFieldTest()method to newly added constraints.This is for
xdecimalfield stress testing using random generated value, min and max.I think it might be overhead to run this method each time in automatic testing but for debugging purposes you can change "run" prefix for "test" and see what happens.
Comment #9
drugan commentedOkay, now the module has a great test coverage so there shouldn't be bugs anymore.
Closing it.