- Issue created by @tstoeckler
- Merge request !8580Draft: Fix DecimalFormatter::numberFormat() for NULL value → (Open) created by tstoeckler
- Status changed to Needs work
7 months ago 7:42am 29 June 2024
\Drupal\Core\Field\Plugin\Field\FieldFormatter\NumericFormatterBase::viewElements()
calls:
$this->numberFormat($item->value);
Since the item may belong to a field that is not required, it is completely valid for $item->value
to be NULL
.
\Drupal\Core\Field\Plugin\Field\FieldFormatter\DecimalFormatter::numberFormat()
pases this value directly to PHP's number_format()
:
protected function numberFormat($number) {
return number_format($number, $this->getSetting('scale'), $this->getSetting('decimal_separator'), $this->getSetting('thousand_separator'));
}
This triggers the following notice:
Deprecated function: number_format(): Passing null to parameter #1 ($num) of type float is deprecated in Drupal\Core\Field\Plugin\Field\FieldFormatter\DecimalFormatter->numberFormat() (line 68 of core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/DecimalFormatter.php).
Check for NULL
either directly in NumericFormatterBase
or in DecimalFormatter->numberFormat()
.
Needs work
11.0 🔥
The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.