Error: [] operator not supported for strings in HOOK_form_alter()
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3345337. --> Reported by: [fanton](https://www.drupal.org/user/128756) Related to !2 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>When accessing to view the documentation generated for a project that includes _form_alter that adds a class, it crashes the site:</p> <blockquote><p>The website encountered an unexpected error. Please try again later.<br> Error: [] operator not supported for strings in MYTHEME_form_alter() (line ... of themes/custom/MYTHEME/MYTHEME.theme). </p></blockquote> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>Have a custom theme or module that uses HOOK_form_alter and adds a CSS class to the forms, for example:</p> <pre>function MYTHEME_form_alter(&amp;$form, &amp;$form_state, $form_id) {<br>if (array_key_exists('#attributes', $form)) {<br>&nbsp;&nbsp;&nbsp; $form['#attributes']['class'][] = 'my-custom-class';<br>&nbsp; }<br>}</pre><h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Change:</p> <p><code>$form['#attributes']['class'] = 'api-search-form';</code></p> <p>To:</p> <p><code>$form['#attributes']['class'] = ['api-search-form'];</code></p> <p>in SearchForm.php, buildForm function, line 34.</p>
issue