Problem/Motivation

When enabling and saving the "Number field-based boosting" processor in Drupal 11 (where deprecation warnings are shown by default in development environments), PHP warnings are triggered:

Warning: Undefined array key "boosts" in Drupal\search_api\Plugin\search_api\processor\NumberFieldBoost->submitConfigurationForm() (line 101 of modules/contrib/search_api/src/Plugin/search_api/processor/NumberFieldBoost.php).

Warning: foreach() argument must be of type array|object, null given in Drupal\search_api\Plugin\search_api\processor\NumberFieldBoost->submitConfigurationForm() (line 101 of modules/contrib/search_api/src/Plugin/search_api/processor/NumberFieldBoost.php).

This occurs because the submitConfigurationForm() method attempts to iterate over $values['boosts'] without checking if the key exists first.

When the processor is initially enabled and saved without any field configurations, the boosts key may not be present in the form values.

Steps to reproduce

  1. Install Drupal 11 with the Search API module.
  2. Create a Search API index with a Database or Solr backend.
  3. Navigate to the index’s Processors configuration page.
  4. Enable the "Number field-based boosting" processor.
  5. Save the processor configuration without configuring any boost fields.
  6. Observe PHP warnings in the logs or on-screen (if error display is enabled)

The same issue affects the TypeBoost processor, though it already has partial defensive checks in place.

Proposed resolution

Use the null coalescing operator (?? []) to provide a default empty array when the boosts key is not present.

Before:
foreach ($values['boosts'] as $field_id => $settings) {

After:
foreach ($values['boosts'] ?? [] as $field_id => $settings) {

This defensive programming practice prevents warnings and gracefully handles cases where no boost configurations have been set yet.

Remaining tasks

Issue fork search_api-3550113

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

gxleano created an issue. See original summary.

ishani patel made their first commit to this issue’s fork.

ishani patel’s picture

Assigned: Unassigned » ishani patel

@gxleano, I've been facing the same issue and have resolved it.
Raised MR, kindly check and review.

Thank you!

ishani patel’s picture

Assigned: ishani patel » Unassigned
Status: Active » Needs review
gxleano’s picture

Thanks @ishani patel, it is already working as expected

So, moving to RTBC.

gxleano’s picture

Status: Needs review » Reviewed & tested by the community
drunken monkey’s picture

Component: General code » Plugins
Status: Reviewed & tested by the community » Fixed

Thanks for reporting this problem, @gxleano, and thanks @ishani patel for providing the MR.
Seems simple enough, and it’s clear how this would happen. We can probably also get away with not providing a regression test for this.
So, merged. Thanks again!

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

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

Maintainers, please credit people who helped resolve this issue.

drunken monkey’s picture

Issue tags: +Vienna2025

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.