I began getting errors on my site when using the latest version of this module.
Warning: Invalid argument supplied for foreach() in element_children() (line 6433 of /includes/common.inc).
The issue seems to be with webform_hints.module:129 where $element is not an array, and it is being passed to element_children, which expects it to be an array.
Adding the following code right above the foreach loop seems to fix it, but I'm not sure what all of the potential implications of this are.
<?php
// Verify that the element is a themeable array.
if (!is_array($element)) {
return;
}
?>
If we want to add this check I'll roll a patch and submit it.
Comments
Comment #1
adamzimmermann commentedComment #2
guschilds commentedThis is likely a bug coming from custom code or a contrib module. I was unable to reproduce this when creating a webform with every type of element in Webform.
element_children()is first called on line 112. If you look at the function, it only acts on array items that don't have a key that begins with '#'. In $form['submitted'], the only array items whose key doesn't begin with '#' are webform components (or are inside of a '#'-keyed array). If all custom elements follow this pattern, the error should never happen. Could you debug a bit more and determine what the rogue array item is?That being said, it may save others from headaches when working with their own custom code or contrib modules if we went ahead and put in a check for this anyway. There is no negative implications for doing so, because right after that
foreachis a check forisset($element['#type']). A non-array will, of course, fail this check and nothing else will come ofwebform_hints_add_title(). Let's see what the true source of the problem is before doing so.Comment #3
adamzimmermann commentedHere is what a little more digging turned up.
The error appeared four times, and there were four items in the
$form['submitted']array that had a value ofNULL. Each of them were keyed by the name of a fieldset.http://monosnap.com/image/TWTfxqywbgiEwvD7EHhpT3c6j87xTx
In a stripped down version of Drupal the issue appears when using a page break in conjunction with fieldset form items.
http://monosnap.com/image/nfb79W1gvfci8akBbS3rrp2KFOE9rv
So it's definitely something that should be accounted for.
We could add an an
is_arraycheck before the initial call towebform_hints_add_title()in the thewebform_hints_form_alter()function, but then that wouldn't handle recursive cases, so I'm going to stand by my original suggestion of adding the check at the beginning ofwebform_hints_add_title().Comment #4
guschilds commentedInteresting. Yup, definitely something to account for.
I'd agree that wrapping both calls to
webform_hints_add_title()with anis_array()check makes less sense than your initial suggestion.Thanks for getting to the bottom of this!
Comment #5
mhamed commentedHere the same once I uploaded a youtube video via media browser
using the modules : media_youtube displayed as a rendered file on a drupal 7.28 installation:
i ve got this :
Warning: Invalid argument supplied for foreach() in element_children() (line 6433 of /Users/sites/drupal/includes/common.inc).Added to an other error:
Warning: Illegal string offset '#children' in drupal_render() (line 5898 of /Users/sites/drupal/includes/common.inc).:repeated on lines:
5898
5908
5946
5953
Comment #6
guschilds commentedWe should get this cleaned up. Can you create a patch for your solution, adamzimmermann?
Comment #7
adamzimmermann commentedPatch attached!
Comment #8
kamescg commentedI am also receiving the same error as mhamed with the Youtube Media Module installed.
Comment #10
guschilds commentedThe patch provided by adamzimmermann in #7 was RTBC and has been committed.
Using the latest dev snapshot should prevent this error from happening further. This will also be included in the next release.
Thanks!
Comment #12
golubovicm commentedI'm getting this error but also some other, similar and only after logging in:
Warning: Invalid argument supplied for foreach() in element_children() (line 6433 of ... /includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5898 of ... /includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5908 of ... /includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5946 of ... /includes/common.inc).
Warning: Illegal string offset '#printed' in drupal_render() (line 5953 of ... /includes/common.inc).
And I'm not using webform module at all?!
Comment #13
ehsankhfr commented#2 is completely right!
"This is likely a bug coming from custom code or a contrib module. "
Try to find & check the modules which are running on the related page of error!