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

adamzimmermann’s picture

Issue summary: View changes
guschilds’s picture

This 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 foreach is a check for isset($element['#type']). A non-array will, of course, fail this check and nothing else will come of webform_hints_add_title(). Let's see what the true source of the problem is before doing so.

adamzimmermann’s picture

Here 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 of NULL. 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_array check before the initial call to webform_hints_add_title() in the the webform_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 of webform_hints_add_title().

guschilds’s picture

Interesting. Yup, definitely something to account for.

I'd agree that wrapping both calls to webform_hints_add_title() with an is_array() check makes less sense than your initial suggestion.

Thanks for getting to the bottom of this!

mhamed’s picture

Here 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

guschilds’s picture

Assigned: Unassigned » adamzimmermann

We should get this cleaned up. Can you create a patch for your solution, adamzimmermann?

adamzimmermann’s picture

Assigned: adamzimmermann » guschilds
Status: Active » Needs review
StatusFileSize
new652 bytes

Patch attached!

kamescg’s picture

I am also receiving the same error as mhamed with the Youtube Media Module installed.

guschilds’s picture

Status: Needs review » Fixed

The 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!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

golubovicm’s picture

I'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?!

ehsankhfr’s picture

#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!