Problem/Motivation
In PHP 8.1 and higher, the custom_field module triggers multiple "Undefined array key" warnings within NumericTypeBase.php. These occur because the class attempts to access settings keys such as 'unsigned' and 'type' directly without verifying if they exist in the settings array.
While these are warnings, they can lead to extreme performance degradation (up to 60-second timeouts) in environments where error handlers (like Sentry or OpenSearch) are active. This is especially prevalent on forms with high-cardinality fields, as a single AJAX "Add more" action rebuilds all existing items, triggering hundreds of warnings and backtrace captures in a single request.
Steps to reproduce
- Use an environment running PHP 8.1 or later.
- Create or use an existing entity with a
customfield type that includes at least one numeric subfield (e.g., Integer). - Add multiple items to this field (e.g., cardinality of 10+).
- Perform an AJAX action on the form (like clicking "Add another item").
- Check the Drupal watchdog logs for
Warning: Undefined array key "unsigned" in Drupal\custom_field\Plugin\CustomField\FieldType\NumericTypeBase::getDefaultMinValue().
Proposed resolution
Update src/Plugin/CustomField/FieldType/NumericTypeBase.php to use null-coalescing operators or !empty() checks when accessing settings keys that may not be explicitly set in older configurations or migrated data.
Remaining tasks
- Review the attached patch.
- Verify that warnings are silenced on PHP 8.1+.
- Ensure no regression in logic for fields where 'unsigned' is explicitly set to TRUE.
User interface changes
None.
API changes
None.
Data model changes
None. The patch only adds safety checks for runtime array access.
| Comment | File | Size | Author |
|---|---|---|---|
| custom_field-php8-compatibility-fixes.patch | 1.06 KB | heyyo |
Issue fork custom_field-3574550
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
apmsooner commentedThanks, if you can check out the branch in the issue fork i just created and apply those changes there, it will run the tests and be easier to merge. Either way, I will make sure this gets resolved for the next release which I am planning soon as I finish up the SDC formatter feature for that.
Comment #6
apmsooner commentedI followed the steps and could only trigger the unsigned error in the field settings form. It never triggered during ajax updates in multi-valued add and I never could trigger anything for the undefined type which it shouldn't as there should always be a type so... I'm merging the fix for the unsigned issue and if you see the other one pop back up somewhere, please open another issue and help me track it. Thank you for the patch :)
Comment #7
apmsooner commentedComment #9
apmsooner commented