FieldType DecimalItem may fail with a TypeError in preSave

Created on 30 December 2024, 4 months ago

Problem/Motivation

I wonder about strict types in the context of \Drupal\Core\Field\Plugin\Field\FieldType\DecimalItem::preSave. It calls

round($this->value, $this->getSetting('scale'))

which throws a TypeError exception on PHP 8.3 and later if $this->value happens to be a string. This can happen easily if a module calls ->setValue($value) and where $value may be a string, like e.g. received from a custom form or an external API.

Proposed resolution

Type casting the value before being passed to the round method.

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

field system

Created by

🇩🇪Germany jurgenhaas Gottmadingen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024