Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291721

Decimal and Float item generates wrong sample values

$
0
0

Problem/Motivation

Generating decimal values does not respect the min and max values.

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Field%21P...

$max = is_numeric($settings['max']) ?: pow(10, ($precision - $scale)) - 1;
$min = is_numeric($settings['min']) ?: -pow(10, ($precision - $scale)) + 1;

This should be turned into normal ternary operator because is_numeric() returns boolean value.

Steps to reproduce

Steps to reproduce.

  1. Add field of type Number (Decimal) to some content type
  2. Set minimum and maximum options for this field
  3. Generate sample data using Devel generate module
  4. Verify that generated value for this field is always 1.00.

Proposed resolution

Change the min/max for float and decimal to something like this:

    $max = is_numeric($settings['max']) ? $settings['max'] : pow(10, ($precision - $scale)) - 1;
    $min = is_numeric($settings['min']) ? $settings['min'] : -pow(10, ($precision - $scale)) + 1;

Remaining tasks

Review
Commit

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A


Viewing all articles
Browse latest Browse all 291721

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>