I am getting the following warning when trying to enable the views module without having CTools enabled.

Warning: Invalid argument supplied for foreach() in element_children() (line 6046 of [path]\includes\common.inc).

If I enable both Views and CTools at the same time there is no error message.

Comments

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

Can you give us any kind of information how to reproduce the problem?

One thing that would might help is to write dvm(views_trace()) in element_children with a if() wrapped.
So you could find out which function calls this.

tsvenson’s picture

Tried to reproduce it on a fresh install, but couldn't. I have a db backup where it happens though which I can attach. It requires quite a few other contribs though...

Before I do that I could test the views_trace you mention, however i am not a coder so it would be great if you could explain how I do the if() wrapped your talking about. Would be great if you can give me the whole element_children function with that so I can just paste it in.

dawehner’s picture


function element_children(&$elements, $sort = FALSE) {
  // Do not attempt to sort elements which have already been sorted.
  $sort = isset($elements['#sorted']) ? !$elements['#sorted'] : $sort;

  // Filter out properties from the element, leaving only children.
  $children = array();
  $sortable = FALSE;
  foreach ($elements as $key => $value) {

Should be


function element_children(&$elements, $sort = FALSE) {
  // Do not attempt to sort elements which have already been sorted.
  $sort = isset($elements['#sorted']) ? !$elements['#sorted'] : $sort;

  // Filter out properties from the element, leaving only children.
  $children = array();
  $sortable = FALSE;
  if (!is_array($elements) && function_exists('views_trace')) {
    dsm(views_trace());
  }
  foreach ($elements as $key => $value) {

You need devel module installed for this.

tsvenson’s picture

Tried with adding your code, but it didn't output anything. Doesn't the views_trace() function require that the Views module is enabled first? This happens when I try to enable it.

dawehner’s picture

Oh interesting.
It's really important that you give more context on your issues.
Take sure you try out to reproduce this bug on a clean drupal installation. The error could be caused by many other things.

tsvenson’s picture

The only way I seem to be able to reproduce it is using a Backup and Migrate database that enables a bunch of modules. Then I simply try and enable the Views module only and that will trigger it. I have attached the database to this comment so you can test it.

You need the following modules and versions (they are all up-2-date when I post this):

Advanced help 7.x-1.x-dev (2011-Feb-25)
Backup and Migrate 7.x-2.1
Comment Notify 7.x-1.x-dev (2011-Feb-25)
Diff 7.x-2.0-beta2
Flexible Blogs 7.x-1.x-dev (2011-Feb-25)
Follow 7.x-1.x-dev (2011-Mar-10)
Gravatar integration 7.x-1.1
Token 7.x-1.0-beta1
Wysiwyg 7.x-2.0

Then you of course need the latest dev versions of Views and C-Tools as well.

Then simply do the following:

  1. Install D7 with standard profile.
  2. Enable the Backup And Migrate module
  3. Restore the attached database
  4. Try and enable the Views module only

UID1 is: Admin/admin

I get the OP error when Drupal says that it needs to enable the ctools module. If I try with enabling them both at the same time there is no error on screen or in the error log.

I am using Acquia DAMP 1.2.33 localy on my Win 7 64bit when this is happening.

Letharion’s picture

There's too many modules involved. I doubt someone else will be interested in digging through them all to find out which one causes the problem. You need to reduce the number of involved modules as much as possible, which will most likely be 1. And even then there's a major risk you'll be asked to file an issue with that module instead of Views.

tsvenson’s picture

Will see what I can do over the weekend. I'm no coder so I can only promise a trial and error search to limit things down. Just think it is a little strange that the error comes only when the C-Tools dependency kicks in. No other module with dependency like this showed similar error on that page, only Views.

brianhinkley’s picture

This error occurs with other modules also.

I get this error when I enable a module that is dependent on another module that isn't enabled.

That error appears just before the the message...

You must enable the ***missing*** modules to install ***this-module***. (***fill in the blank***)
Would you like to continue with the above?
continue cancel

I haven't noticed any affect on the function of the installed modules after clicking continue and the installation completes.

There may be other instances where this occurs. I know I can duplicate it every time by enabling modules with dependencies.

Letharion’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

So this might be a core issue, and it might not. With the information available at the moment, there is nothing we can do, and regardless, it's questionable at best whether or not this is Views related.

ansorg’s picture

I guess it's not views related at all. I run just into it. Fres D7 install, I started with minimal profile. Enabled some more modules but not yet Views. I didn't pay attention when the warning appeared the first time but now I have attached a debugger and I see that the following stack trace

Remote Launch (suspended)	
	D7-dropbox/includes/common.inc.element_children : lineno 6046() D7-dropbox/includes/common.inc at line 6046	
	D7-dropbox/sites/all/modules/advanced_help/advanced_help.module.advanced_help_form_system_modules_alter : lineno 322() D7-dropbox/sites/all/modules/advanced_help/advanced_help.module at line 322	
	D7-dropbox/includes/module.inc.drupal_alter : lineno 1002() D7-dropbox/includes/module.inc at line 1002	
	D7-dropbox/includes/form.inc.drupal_prepare_form : lineno 1038() D7-dropbox/includes/form.inc at line 1038	
	D7-dropbox/includes/form.inc.drupal_rebuild_form : lineno 451() D7-dropbox/includes/form.inc at line 451	
	D7-dropbox/includes/form.inc.drupal_process_form : lineno 900() D7-dropbox/includes/form.inc at line 900	
	D7-dropbox/includes/form.inc.drupal_build_form : lineno 350() D7-dropbox/includes/form.inc at line 350	
	D7-dropbox/includes/form.inc.drupal_get_form : lineno 188() D7-dropbox/includes/form.inc at line 188	
	D7-dropbox/includes/menu.inc.call_user_func_array : lineno 501() D7-dropbox/includes/menu.inc at line 501	
	D7-dropbox/includes/menu.inc.menu_execute_active_handler : lineno 501() D7-dropbox/includes/menu.inc at line 501	
	D7-dropbox/index.php.{main} : lineno 22() D7-dropbox/index.php at line 22	

the advanced_help.module.advanced_help_form_system_modules_alter sends a $form['modules'] to common.inc.element_children() which is undefined

move to Advanced Help?

ansorg’s picture

Status: Closed (cannot reproduce) » Active
dawehner’s picture

Project: Views (for Drupal 7) » Advanced Help
Version: 7.x-3.x-dev » 7.x-1.x-dev

Yes, move to advanced help.

Thanks! for provide a backtrace. This is great!!

skruf’s picture

Status: Active » Needs review
StatusFileSize
new1.48 KB

This patch checks the $form['modules'] variable is set before sending to common.inc > element_children().

yordan’s picture

In function advanced_help_form_system_modules_alter(&$form, &$form_state)
$form['modules'] can be undefined.

What solves this problem for me is a simple check before executing the outer loop:
if (isset ($form['modules'])) {
foreach...
}

fietserwin’s picture

Status: Needs review » Reviewed & tested by the community

Problem occurs when the modules list form gets back to ask permission to enable required modules. in that case there is no list of modules on the form. So the patch is the correct solution and works for me.

Only remark could be to also test if $form['modules'] is an array if it is set, but the context will probably ensure that it is either not set or it is an array.

pasqualle’s picture

I can confirm this bug, and the patch is ok

eMPee584’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new614 bytes

Yes, the analysis is correct (empty form['modules'] on "Some required modules must be enabled" confirmation page) and the patch does work. But imho it's a little cleverer to exit the function straight away, also that way the indentation depth doesn't increase further -> no whitespace diff...

fietserwin’s picture

Status: Needs review » Reviewed & tested by the community

That's a matter of style and personal preference. Personally, I prefer the "1 exit point only" coding style (#14), but I don't care that much. e.g., if in the future you would want to alter another part of the form, you will have to revert to the way #14 does it anyway.

However, #18 is functionally equivalent to #14, so pick one and please commit it.

eMPee584’s picture

@fietserwin: well the difference it makes is

  • smaller diff :)
  • one less function call because it aborts earlier

but your point's valid too so..

fietserwin’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.5 KB

Good catch. That function call should be in the if as well ... Reroll of #14. Please make your choice between #18 and #21 ...

rob c’s picture

Because it's so darn close to the line #nr i'll try it here first:

Warning: Invalid argument supplied for foreach() in element_children() (line 6161 of [path]/includes/common.inc).

That's on D7.10, Advanced Help 7.x-1.0 and Advanced Help 7.x-1.x-dev 25 feb. 2011. (also have backup migrate installed, but that's really all)

I get the error when i try to install Pathauto 7.x-1.0 if i don't select token, it shows up on the confirmation page. If it's not related i'll dive into it if time permits and roll a separate issue, but first let's try here.

(so, clean install of drupal + contact, content translation, trigger, tracker core modules + backup migrate and advanced help Installed, then select pathauto and hit install)

fietserwin’s picture

Title: Invalid argument when trying to enable latest dev » Invalid argument supplied for foreach() when asking confirmation to enable required modules

- Clarified title.
- #22: Probably the same, common.inc has been changed since the original report.
- Can someone else RTBC (latest patch is mine)?

petsagouris’s picture

Status: Needs review » Reviewed & tested by the community

This works fine, thanks a lot.

kingfisher64’s picture

I keep getting 6161 error on common.inc. I debugged this with some help and it was traced back to advanced help. The error used to pop up when a module was being installed. I'd click save and carry on and everything appears to be working fine. It got very annoying having to deal with this everytime a mod was enabled.

Since i've stopped using the module the error no longer pops up. I'd really like to be using the mod. Is there any plans to fix this?

I'd be willing to provide any info necessary. I was using 7.10 now i'm using 7.12 - and have not installed the mod with that yet.

Thanks

kingfisher64’s picture

I'm getting different 6xxx thousand errors all to do with common.inc.element_children() when installing other modules.

Does the patches on #18 + #21 fix these error notices? If so could a new patched version of advanced help be released?

twistor’s picture

Works.

amitgoyal’s picture

Status: Reviewed & tested by the community » Fixed

Thanks all! It's been moved into 7.x-1.x-dev.

Status: Fixed » Closed (fixed)

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