Skip to content

introduce AbstractFormattedNumberOutputHandler

This change introduces a superclass for all the output handlers that include configuration options for number formatting (number of decimals, decimal and thousand separators, prefix and suffix) so that a good amount of code can be deduplicated and gathered in the new superclass. Code in the inheriting classes is deleted where the same code appears in one of its ancestors in the inheritance tree. Some changes are introduced along the way:

  • In buildConfigurationForm, the local variable defaults is turned into a protected class member that subclasses have to use after calling parent::buildConfigurationForm. Also, subclasses need to ensure they call $form->setDefaults($this->defaults) themselves if $field['configuration'] is set even if they do not add anything to the defaults. This is because from inspecting the code I found that $form->setDefaults should not be called twice, so buildConfigurationForm in the new superclass adds five defaults but does not call the method.
  • A small change was made to the help texts in the configuration form that asks for formatting parameters. The $ sign is now suggested as a prefix and the € sign as a suffix. To suggest € as a suffix is in line with the majority of the EU’s languages, see this source, section “Position of the euro sign (€) in amounts”, and note that while the English text suggests the prefix position, it also mentions that this only applies in (English implicitly, Dutch is omitted), Irish and Maltese. The Dutch version is worded accordingly. Switching to another language such as German yields a version that does suggest € as a suffix (while still mentioning the change in these four languages). The suggestion of $ as a prefix is of course the correct usage in the US dollar’s “native language”.
  • The setting of $this->outputFieldSpec->type is changed in most cases. In NumberFieldOutputHandler, CalculationFieldOutputHandler and AggregateFunctionFieldOutputHandler it is set to 'Float'. Up to now, AggregateFunctionFieldOutputHandler copies the type from $this->inputFieldSpec->type and the other two use 'String'. After consultation with Jaap Jansma, the agreed position is that the type reflects the raw value and for all these fields the raw value is guaranteed to be float via a cast or the declared result of a function. In SubtractFieldOutputHandler no change of behaviour is introduced by the code change because it did set 'Float' already.

The Expenses extension also contains an output handler that can become a child class of the new superclass. A merge request will appear there too.

Merge request reports