Support decimals with new field type, widget and formatter

Created on 27 June 2025, about 11 hours ago

Problem/Motivation

I (and I guess many others) needed to reference entities with a decimal quantity attached. That can represent, for example, ownership shares, that are are quite common but not easy to support with the current schema.
The code required is so similar to the current module that it wouldn't make sense to create a new one imho, so I would like to add a new Field Type, 2 Widgets, and 2 Formatters, that mimic the existing ones, but are called "Share" instead of "Quantity". The only difference would be to have a decimal in the schema, and the only additions would be:

  1. to have configurable field storage settings for the decimal precision & scale (note that floats are not suited for shares, since precision is required in administrative contexts)
  2. a validation constraint, to check the sum of shares is not more than the max share value set in the field settings (especially useful for multivalued fields)
  3. the decimal places & separator settings in the formatter, as well as the option to hide trailing zeroes

Remaining tasks

  1. Provide the Merge Request
  2. Community Test & Review of the features
  3. Inclusion in a new release

User interface changes

When creating a new field, under "Reference" there will be a new option "Entity reference w/share" after the existing "Entity reference w/quantity", and similarly all field settings, formatters' & widgets' labels would mention shares instead of quantities, but keep the same structure.

📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇮🇹Italy kopeboy Milan

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