Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Move number formatters to the new API
Move number formatters to the new API
Comments
Comment #1
pcambraComment #2
pcambraHere's the commit in my branch: 89abbac
I was doubting when transforming this if we should implement just one Default formatter for integer and decimal as the code is almost equivalent, but that would mean more changes.
Comment #3
yched CreditAttribution: yched commentedThanks @pcambra !
There does need to be different classes for integer and decimal 'default' formatters, because they have different default settings, but given the code in the methods, it seems they would really benefit from sharing a common base class.
- At least for the code about prefixes/suffixes in viewElements() should be shared in a method in the parent
(also, beware, in your code this code is wrapped in an
if ($this->getSetting('thousand_separator')) {
that should be about setting 'prefix_suffix' instead)- settingsForm() could probably be in the parent as well :
something like :
(IMO we do want to get rid of the "dummy" settings on number_integer, that are only used for their default values : scale, decimal_separator)
Comment #4
pcambraHere's a new version: commit
I had some stupid merge problems, but here's a good interdiff.
I couldn't implement the common settings form as getDefaultSettings is returning all of them for both of the formatters.
Back to CNR
Comment #5
yched CreditAttribution: yched commentedAdjusted the code organisation and bit, and merged into field-plugins-formatters-1785748.
Thanks !