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

  1. Have a project where the configuration keys classes.region and/or classes.field are missing or set to null.
  2. Go to the Classes settings page.
  3. Observe the fatal TypeError caused by implode() receiving null instead 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

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

johnatas created an issue. See original summary.

johnatas’s picture

Status: Active » Needs review

I have opened a merge request implementing the proposed safeguard by adding an empty array fallback when classes.region or classes.field configuration is missing.

swentel’s picture

Patch makes sense, even if it's hard to reproduce. Will merge in a couple of minutes and trigger a new release.

  • johnatas committed 11304950 on 8.x-3.x
    #3573447: Add empty array fallback to prevent errors
    
swentel’s picture

Status: Needs review » Fixed

Merged in, triggering a new release.

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.

swentel’s picture

Status: Fixed » Closed (fixed)