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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3556523-responsive_favicons-implode-typeerror-fix.patch | 899 bytes | mdeahmad |
Issue fork responsive_favicons-3556523
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
Comment #2
mdeahmadAdding A patch for That
Comment #5
mably commentedComment #7
mably commented