DecimalItem should not use String as its DataDefinition

Created on 23 June 2017, over 7 years ago
Updated 24 July 2023, over 1 year ago

Decimal field is being serialized as "null" instead of "0.0" when the value is empty. However, in other languages, such as Java or SQL, "null" is not allowed for decimal primitive.

This is because DecimalItem is being defined as "string" in core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php

 /**
   * {@inheritdoc}
   */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties['value'] = DataDefinition::create('string')
      ->setLabel(t('Decimal value'))
      ->setRequired(TRUE);

    return $properties;
  }

Proposed solution:

change the "string" definition to "decimal"

šŸ› Bug report
Status

Fixed

Version

11.0 šŸ”„

Component
FieldĀ  ā†’

Last updated 1 day ago

Created by

šŸ‡ØšŸ‡³China skyredwang Shanghai

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024