Error: [] operator not supported for strings in Drupal\conditional_fields\ConditionalFieldsFormHelper->addJavascriptEffects() (line 289 of modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php).

Patch needed.

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

drupalfan2 created an issue. See original summary.

drupalfan2’s picture

dhruv.mittal’s picture

Assigned: Unassigned » dhruv.mittal

dhruv.mittal’s picture

Assigned: dhruv.mittal » Unassigned
Status: Active » Needs review

As patch is deprecated and it is easier to review MR, for that reason I've raised MR from the given patch.
Thanks!

benstallings’s picture

Status: Needs review » Reviewed & tested by the community

Claude Code says:

This fixes a crash when $this->form['#attached']['library'] is a string instead of the expected array, which would cause [] (array push) to fail.

It works, but it's papering over a problem upstream — #attached['library'] should always be an array per the Drupal render API. If it's a string, something else set it incorrectly. That said, being defensive here is reasonable since this module processes arbitrary forms it doesn't control.

Minor style nit: The wrapped string value has inconsistent indentation (missing 2 spaces). Should be:

  $this->form['#attached']['library'] = [
    $this->form['#attached']['library'],
  ];

Verdict: Acceptable defensive fix. I'd fix the indentation before merging. Optionally, could also be simplified to just always cast it:

$this->form['#attached']['library'] = (array) ($this->form['#attached']['library'] ?? []);

But the current approach is fine with the indent fix.