Problem/Motivation
Continuing on from needing to
✨
Use batching for post update functions
Closed: won't fix
, sites with old Fraction fields will encounter the following php notices as the field did not previously have the min, max, prefix or suffix keys set in settings. The code in core and in Fraction assumes that these keys exist without any checks.
Viewing or editing an entity with an old and now updated Fraction field results in an error message like this:
Notice: Undefined index: prefix in Drupal\fraction\Plugin\Field\FieldWidget\FractionDecimalWidget->formElement() (line 99 of /[path]/web/modules/contrib/fraction/src/Plugin/Field/FieldWidget/FractionDecimalWidget.php)
Notice: Undefined index: suffix in Drupal\fraction\Plugin\Field\FieldWidget\FractionDecimalWidget->formElement() (line 103 of /[path]/web/modules/contrib/fraction/src/Plugin/Field/FieldWidget/FractionDecimalWidget.php)
Viewing the field settings will give an error message such as:
Notice: Undefined index: min in Drupal\Core\Field\Plugin\Field\FieldType\NumericItemBase->fieldSettingsForm() (line 35 of /[path]/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php)
Notice: Undefined index: max in Drupal\Core\Field\Plugin\Field\FieldType\NumericItemBase->fieldSettingsForm() (line 41 of /[path]/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php)
Saving the field settings clears up the issue, but an automated method helps.
Again, probably relegated to the "maybe later" pile, but maybe it'll help someone else out too.
Steps to reproduce
- Have Fraction 8.x-1.x installed on an old D8 site and upgrade to Fraction 2.x.
- Run post-updates in
✨
Use batching for post update functions
Closed: won't fix
to make it useable
- View any entity with a Fraction field on it
- OR edit the field settings for any Fraction field on one of those entities
Proposed resolution
Add a post-update function to re-save the Field Instance Configs, which automatically fixes the problem by merging in default settings during the preSave method.
Remaining tasks
None
User interface changes
None
API changes
None
Data model changes
None