Deprecated function: Passing null to str_starts_with() in MaterialIcons->getFontFamilyClass()

Created on 18 July 2025, 29 days ago

Problem/Motivation

When using material_icons with PHP 8.1 or above and Drupal 10.4.7, I receive this error:

Deprecated function: str_starts_with(): Passing null to parameter #2 ($needle) of type string is deprecated in Drupal\material_icons\Plugin\Field\FieldFormatter\MaterialIcons->getFontFamilyClass() (line 149 of modules/contrib/material_icons/src/Traits/MaterialIconsSettings.php).

It looks like this is due to passing null as the $needle argument.

Steps to reproduce

  • Install material_icons on PHP 8.1+
  • Add a Material Icons field to an entity and render it.

Proposed resolution

Add a check to ensure both parameters are strings before calling str_starts_with().

๐Ÿ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States cmah

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

Merge Requests

Comments & Activities

  • Issue created by @cmah
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cmah
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia abhishek_virasat

    abhishek_gupta1 โ†’ made their first commit to this issueโ€™s fork.

  • Merge request !13fix the issues โ†’ (Open) created by abhishek_virasat
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia abhishek_virasat

    @cmah, I have fixed the issue and created MR, please review it once.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cmah
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States benjifisher Boston area

    I am working on the same project as @cmah.

    On our site, the font family is saved as an empty string in the database:

    mysql>  SELECT entity_id, field_hwp_icon_icon, field_hwp_icon_family, field_hwp_icon_classes FROM paragraph__field_hwp_icon;
    +-----------+---------------------+-----------------------+------------------------+
    | entity_id | field_hwp_icon_icon | field_hwp_icon_family | field_hwp_icon_classes |
    +-----------+---------------------+-----------------------+------------------------+
    |         4 | cabin               |                       | NULL                   |
    |         6 | 30fps               |                       | NULL                   |
    |         7 | phone_android       |                       | NULL                   |
    +-----------+---------------------+-----------------------+------------------------+
    3 rows in set (0.00 sec)
    

    I am not sure why that is. We are using the paragraphs and paragraphs_layout modules, and some custom code. But this did not cause problems with Version 2.0.1, so I consider it a bug in this module. (Perhaps it is a bug that is only exposed when there are bugs in other parts of the system.)

    I am updating the "Steps to reproduce" in the issue summary.

Production build 0.71.5 2024