I was getting a fatal error because the taxonomy term was a required field. In testing, I left the field empty and it comes back as a string (class="class names"), not an array as expected in textfield.func.php. To fix, I added a test (line 27):

if (is_array($element['#attributes']['class'])) {
      $element['#attributes']['class'][] = 'form-autocomplete';
    } else {
      $class_attr = explode('"', $element['#attributes']['class']);
      $class_attr[1] = $class_attr[1] . ' form-autocomplete';
      $element['#attributes']['class'] = implode('"', $class_attr);
    }

Comments

markhalliwell’s picture

Status: Active » Postponed (maintainer needs more info)

This should really be fixed in the module that is setting the $element['attributes']['class'] array as a string. What module is doing it?

RobKoberg’s picture

I am not really sure. I was thinking it was was deep, because it occurs after the form detects that a required field (in this case a taxonomy term reference) was left blank. I am not seeing anything that would do this in any of the taxonomy validate function (e.g. taxonomy_autocomplete_validate)

SiliconMind’s picture

Title: taxonomy term reference, returned on error, no class array for textfield.func.php » Fatal error: [] operator not supported for strings in textfield.func.php

I'm dealing with similar issue. But it has nothing to do with taxonomy term reference. I was trying to nail this but I have no clues.

My scenario:
I've added custom theme hook for node form. As usual I've added a call to devel's "dpm" function to dump function args and be able to easily theme the fields I needed. Then I just called drupal_render_children on a form. I didn't code any theming yet. This was just to test and see how fields are named.

And I got this:
Fatal error: [] operator not supported for strings in /blah/sites/all/themes/bootstrap/theme/system/textfield.func.php on line 27

For some reason for one of the form fields the class was a string, not an array. After few minutes of testing it turned out that after calling dpm() function one of fileds was altered. Don't ask me how. I have no idea. As soon as I removed dpm() call everything started to work. The field that got broken was core's "Authored by".

markhalliwell’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)
Related issues: +#2269653: [bootstrap][policy][7.x-3.x] CSS Classes (Fatal error: [] operator not supported for strings)
DrCord’s picture

I know this issue is closed and marked "will not fix", and that is fine, I agree you shouldn't fix your theme if it isn't broken. However, I needed to work around this issue and could't track the problem back to the originating module, so I wrote a tiny fix that allows your theme to continue to work if contrib modules aren't coded right:

this replaces the code on line 27 of 'sites/all/themes/bootstrap/theme/system/textfield.func.php'

if(!is_array($element['#attributes']['class'])){
          $element['#attributes']['class'] = (array)$element['#attributes']['class'];
      }
      $element['#attributes']['class'][] = 'form-autocomplete';

This isn't intended to be a patch, but instead a bit of help for anyone in the same situation as I was who needed it working despite poorly coded contrib modules.

Zsuffa Dávid’s picture

Like in case #3 removing dpm() solved the issue for me. There was no other module setting class attribute as string.

hazah’s picture

The call to drupal_attributes on line 22 converts the array to a string.

alifarmani’s picture

Drupal version: 7.37
jQuery version: 1.8
Devel version: 7.x-1.5
Boostrap core vers.: 7.x

Hi All,
When I activated Devel Module on Bootstrap theme, and I tried to edit a node, I got this message:

Fatal error: [] operator not supported for strings in C:\xampp\htdocs\mysite\sites\all\themes\bootstrap\theme\system\textfield.func.php on line 27

I either tried to activate Bartik theme, or deactivate Devel Module and in both situations it seemed that the issue was gone.

I couldn't find any resolution for that, so I can use Devel on Boostrap without having problem with node edit.

I hope this is helpful for whom which are amateur in Drupal like me and don't know where the issue comes from!

Thank you