IconManagerService::formatSearchTerms() throws error if 'search_terms' is missing

Created on 25 April 2025, 3 days ago

Problem/Motivation

The formatSearchTerms() method in IconManagerService assumes that the search_terms property exists and is always an array. However, if an icon is missing search_terms (or it is NULL), the method will trigger a fatal TypeError:

TypeError: array_push(): Argument #1 ($array) must be of type array, null given in array_push()

Steps to reproduce

  • Install and enable the Fontawesome Iconpicker Widget module.
  • Use the service fontawesome_iconpicker_widget.icon_manager in custom code (for example, in a field widget plugin).
    Example code calling:
    $term_list = \Drupal::service('fontawesome_iconpicker_widget.icon_manager')->getFormattedTermList();.
  • Ensure at least one FontAwesome icon does not have search_terms populated.
  • Render the form using your widget (or otherwise trigger the code path).
  • Observe a TypeError is thrown:
    TypeError: array_push(): Argument #1 ($array) must be of type array, null given

Proposed resolution

Update formatSearchTerms() to defensively check that $properties['search_terms'] is an array before trying to array_push() into it. If search_terms is missing or NULL, initialize it as an empty array before pushing. This makes the method resilient against incomplete or custom icon metadata.

Remaining tasks

  • Review the attached patch.
  • If the change is deemed useful by the maintainers I can create a merge request.

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States thefancywizard

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024