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

  1. Use an environment running PHP 8.1 or later.
  2. Create or use an existing entity with a custom field type that includes at least one numeric subfield (e.g., Integer).
  3. Add multiple items to this field (e.g., cardinality of 10+).
  4. Perform an AJAX action on the form (like clicking "Add another item").
  5. 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.

Command icon 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

heyyo created an issue. See original summary.

apmsooner made their first commit to this issue’s fork.

apmsooner’s picture

Thanks, 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.

apmsooner changed the visibility of the branch 4.0.x to hidden.

apmsooner’s picture

I 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 :)

apmsooner’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

apmsooner’s picture

Status: Fixed » Closed (fixed)