Calculation fails if a rewrite is set up with a prefix for a referenced field

Created on 15 March 2023, almost 2 years ago
Updated 15 June 2023, over 1 year ago

Problem/Motivation

My reference for the expected behavior is the old 8.x-1.9 version: I'm at work for an update of an old Drupal 8 site.
There I could for sure set up a rewrite pattern for a field containing a price value, to put a "€" character before the number. I had no problem in having that number multiplied by 0.8, I mean the Simple Math Field was taking the number itself, ignoring the rewriting, as if the rewrite rule affected just the way the field was displayed. Passing to Drupal 9 and to version 3.0.1 of the module, the result of the mentioned multiplication is 0 anyway, as long as the rewriting procedure of the source value is active.

Steps to reproduce

  • Creating a view collecting a field containing a number
  • Setting up a rewrite pattern for that field involving some prefix to specify a currency (no problem with suffixes, please read below)
  • Setting up a Simple Math Field to multiply the value related to the mentioned field by some constant (I used 0.8)

The result from Simple Math Field should be 0.
Curiously enough the problem does not occur if some character is set as a suffix of the numeric value, even if the suffix directly follows the numeric value, that is with no blank space in the middle.

Proposed resolution

Reverting the behavior back to the behavior I could rely on with the old 8.x-1.9 version: I could safely set up a rewrite rule to see a prefix for a source field value and see Simple Math Field perform the requested operation on the value, as if the object of the operation was the value itself and not the string resulting from the rewriting. After all, why should Simple Math Field ever work on a value that likely is not a number anymore? Rewriting a value would likely produce a string, wouldn't it?

I take this chance to ask you whether using version 8.x-2.0-beta2 I would have the same problem mentioned above.

Thanks in advance!

Andrea

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇮🇹Italy AppLEaDaY

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

Comments & Activities

Production build 0.71.5 2024