Problem/Motivation
If the configuration keys classes.region or classes.field do not exist, the Classes settings page becomes unusable and triggers a fatal error.
The following errors are thrown:
TypeError: implode(): If argument #1 ($separator) is of type string, argument #2 ($array) must be of type array, null given in implode() (line 29 of modules/contrib/ds/src/Form/ClassesForm.php).
TypeError: implode(): If argument #1 ($separator) is of type string, argument #2 ($array) must be of type array, null given in implode() (line 36 of modules/contrib/ds/src/Form/ClassesForm.php).
It is unclear whether this situation (missing configuration for these keys) is expected or how to reliably reproduce it. The issue was observed on an existing project that had been taken over, where the configuration appeared to be incomplete or missing.
Steps to reproduce
- Have a project where the configuration keys
classes.regionand/orclasses.fieldare missing or set tonull. - Go to the Classes settings page.
- Observe the fatal
TypeErrorcaused byimplode()receivingnullinstead of an array.
Proposed resolution
Add a safeguard in ClassesForm.php to ensure that classes.region and classes.field default to an empty array when the configuration is missing or null.
For example, ensure that the value passed to implode() is always an array by providing an empty array as a fallback. This would prevent the fatal error and make the form more robust in case of incomplete or corrupted configuration.
Issue fork ds-3573447
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 #3
johnatas commentedI have opened a merge request implementing the proposed safeguard by adding an empty array fallback when
classes.regionorclasses.fieldconfiguration is missing.Comment #4
swentel commentedPatch makes sense, even if it's hard to reproduce. Will merge in a couple of minutes and trigger a new release.
Comment #6
swentel commentedMerged in, triggering a new release.
Comment #8
swentel commentedTriggered a new release, thanks!
https://www.drupal.org/project/ds/releases/8.x-3.37