Error: [] operator not supported for strings in Drupal\conditional_fields\ConditionalFieldsFormHelper->addJavascriptEffects() (line 289 of modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php).
Patch needed.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | conditional-fields-operator-not-supported-for-strings-in-ConditionalFieldsFormHelper-3517815-2.patch | 716 bytes | drupalfan2 |
Issue fork conditional_fields-3517815
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
drupalfan2 commentedPatch
Comment #3
dhruv.mittal commentedComment #5
dhruv.mittal commentedAs patch is deprecated and it is easier to review MR, for that reason I've raised MR from the given patch.
Thanks!
Comment #6
benstallings commentedClaude 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:
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.