Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
markhalliwellThis should really be fixed in the module that is setting the
$element['attributes']['class']
array as a string. What module is doing it?Comment #2
RobKoberg CreditAttribution: RobKoberg commentedI 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)
Comment #3
SiliconMind CreditAttribution: SiliconMind commentedI'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".
Comment #4
markhalliwellComment #5
DrCord CreditAttribution: DrCord commentedI 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'
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.
Comment #6
Zsuffa Dávid CreditAttribution: Zsuffa Dávid commentedLike in case #3 removing
dpm()
solved the issue for me. There was no other module setting class attribute as string.Comment #7
hazah CreditAttribution: hazah commentedThe call to
drupal_attributes
on line 22 converts the array to a string.Comment #8
alifarmani CreditAttribution: alifarmani commentedDrupal 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