Problem/Motivation

A PHP TypeError occurs on the Responsive Favicons admin form:

TypeError: implode(): Argument #1 ($array) must be of type array, string given
in implode() (line 100 of /var/www/html/docroot/modules/contrib/responsive_favicons/src/Form/ResponsiveFaviconsAdmin.php).

This happens because the configuration value $config->get('tags') may return NULL or a non-array value, but the code assumes it is always an array and passes it directly to implode().
This results in a fatal error on the admin settings page.

Existing code:

'#default_value' => implode(PHP_EOL, $config->get('tags')),

Remaining tasks

Update the code to handle NULL or non-array return values safely.

Test the fix by clearing cache and reloading the admin configuration page.

Verify that the form loads without errors even when the configuration is empty.

Optionally add a safeguard elsewhere if similar patterns are used.

User interface changes

None. The admin form will behave the same way as before, except it will no longer produce a PHP error when the configuration is missing or invalid.

API changes

None. This is an internal code fix and does not affect public APIs or hooks.

Data model changes

None. No configuration or schema changes are required.

Fixed code:

'#default_value' => implode(PHP_EOL, $config->get('tags') ?: []),

This change ensures that if $config->get('tags') returns NULL or any non-array value, an empty array will be used instead.
That prevents implode() from throwing a TypeError while maintaining intended functionality.

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

mdeahmad created an issue. See original summary.

mdeahmad’s picture

Adding A patch for That

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

mably’s picture

Version: 2.0.1 » 4.x-dev
Assigned: mdeahmad » Unassigned
Status: Active » Needs review

  • mably committed c4341b2f on 4.x
    Issue #3556523 by mdeahmad, mably: TypeError: implode(): Argument #1...
mably’s picture

Priority: Major » Normal
Status: Needs review » 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.

Status: Fixed » Closed (fixed)

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