warning: Invalid argument supplied for foreach() in /var/www/html/www/geekfr/sites/all/modules/mysite/plugins/layouts/default.php on line 27

I get this error the second I activate the default plugin....

Any ideas what's going on?
Thanks,

Patchak

Comments

agentrickard’s picture

Not enough information provided to answer question.

This has been addressed before, so make sure you have the most current version.

http://drupal.org/node/153570
http://drupal.org/node/157164

agentrickard’s picture

Category: bug » support
agentrickard’s picture

Status: Active » Closed (fixed)

Closing due to lack of follow-up.

graysadler’s picture

Status: Closed (fixed) » Active

I got this same error on line 27 layout/default.php. It happened when an item was removed from the page which left only one. When another item was added, the error went away. Let me know if you need any addl information.

agentrickard’s picture

Status: Active » Postponed (maintainer needs more info)

There is still not enough information here. I have some suspicions.

Is the one item that was left part of the default content set? That is, the content pre-set by the administrator?

What user with what roles and permissions did this error occur for? Whose MySite page were they looking at?

A URL and test account would be helpful as well.

agentrickard’s picture

Also please confirm that you are using 5.x.2.8 by changing the Version in the issue.

agentrickard’s picture

One other question:

Does this _only_ happen with the default plugin? Have you changed your layout from a multi-column one?

My suspicion here is that you have content assigned to other page areas and it isn't collapsing properly when you reset to the default layout.

agentrickard’s picture

OK, I was finally able to replicate this error. It happened when I did the following:

1) Selected the two-column layout.
2) Moved all content into the right-hand column.
3) Switched to the default layout.

There is probably an error in mysite_prepare_columns().

Can you confirm that you did something similar before this problem came up?

agentrickard’s picture

Status: Postponed (maintainer needs more info) » Needs review

Try this. Sorry for the lack of a proper patch.

Edit mysite.module, lines 769 - 779, function mysite_prepare_columns():

  if (isset($data[$set])) {
    $data[$set] = array_merge($data[$set], $new);
  }
  else {
    for ($i = $set; $i >= 0; $i--) {
      if (isset($data[$i]) || $i = 0) {
        $data[$i] = array_merge($data[$i], $new);
        break;
      }
    }
  }

To:

  if (isset($data[$set])) {
    $data[$set] = array_merge($data[$set], $new);
  }
  else {
    if ($set == 0) {
      $data[0] = $new;
    }
    else {
      for ($i = $set; $i >= 0; $i--) {
        if (isset($data[$i]) || $i = 0) {
          $data[$i] = array_merge($data[$i], $new);
          break;
        }
      }
    }
  }

I think that the for loop did not execute correctly if the $set == 0.

agentrickard’s picture

Version: 5.x-2.6 » 5.x-2.8
Category: support » bug

More testing. It's easier to replace the entire function mysite_prepare_columns()

function mysite_prepare_columns($mysite, $data = array(), $cols = 1) {
  global $user;
  // set the columns correctly
  $set = $cols - 1;
  if (count($data) == 1) {
    sort($data); // this will reset the key to zero
  }  
  $new = array();
  foreach ($data as $key => $value) {
    if ($key >= $cols) {
      $new = array_merge($new, $value);
      unset($data[$key]);
    }
  }
  if (isset($data[$set])) {
    $data[$set] = array_merge($data[$set], $new);
  }
  else {
    for ($i = $set; $i >= 0; $i--) {
      if (isset($data[$i]) || $i = 0) {
        $data[$i] = array_merge($data[$i], $new);
        break;
      }
    }
  }
  if ($cols > 1) {
    // this only needs to be checked if the user is looking at his or her own page
    if (user_access('administer mysite') || (user_access('edit mysite') && $user->uid == $mysite->uid)) {
      for ($i = 0; $i <= $set; $i++) {
        if (empty($data[$i])) {
          $data[$i][0]['title'] = 'Add content';
          $data[$i][0]['mid'] = NULL;          
          $data[$i][0]['format'] = $mysite->format;
          $data[$i][0]['output']['items'][0]['content'] = theme('mysite_empty_column', $user);
        }
      }
    }  
    $return = $data;
  }
  else {
    $return = $data[0];
  }
  return $return;
}

THis will likely get committed to HEAD this weekend, since this is a bug.

agentrickard’s picture

I ended up refactoring this code (again).

function mysite_prepare_columns($mysite, $data = array(), $cols = 1) {
  global $user;
  // reset the key to zero if there is only one column
  if (count($data) == 0) {
    sort($data); 
  }
  else {
    // otherwise, slide existing data to a new array and unset the old
    $new = array();
    for ($i = 0; $i < $cols; $i++) {
      $new[$i] = $data[$i];
      unset($data[$i]);
    }
    // if there is leftover data, merge it into the last element of the new array;
    if (!empty($data)) {
      // set the columns correctly for the new keys
      $set = $cols - 1;
      if (empty($new[$set])) {
        $new[$set] = array();
      }
      // loop the remaining data and merge it to the last region
      foreach ($data as $array) {
        if (!empty($array)) {
          $new[$set] = array_merge($new[$set], $array);
        }  
      }  
    }
  }
  if ($cols > 1) {
    // this only needs to be checked if the user is looking at his or her own page
    if (user_access('administer mysite') || (user_access('edit mysite') && $user->uid == $mysite->uid)) {
      for ($i = 0; $i < $cols; $i++) {
        if (empty($new[$i])) {
          $new[$i][0]['title'] = 'Add content';
          $new[$i][0]['mid'] = NULL;          
          $new[$i][0]['format'] = $mysite->format;
          $new[$i][0]['output']['items'][0]['content'] = theme('mysite_empty_column', $user);
        }
      }
    }  
    $return = $new;
  }
  else {
    $return = $new[0];
  }
  return $return;
}
agentrickard’s picture

Status: Needs review » Fixed

A modified version of this fix has been rolled into the 5.x.2.9 release.

Nice catch!

tsavino’s picture

Version: 5.x-2.8 » 5.x-2.11
Status: Fixed » Active

When I go to http://www.thesubculture.com/site/mysite when I pick Go to "user MySite page" I get these errors from each of the layouts and this happens with the default garland and litejazz but when I pick "Show list of all user mysites" there is no error these errors happen when the user is not loged in and on the access control I have "view all mysites" for "anonymous user" and made sure that they can view all content. these are the different panel choices

---------------------
Left Sidebar
A large main area with left sidebar:
warning: Invalid argument supplied for foreach() in /home/thesubc/public_html/site/modules/mysite/plugins/layouts/left.php on line 35.
---------------------
Two column
Two equal-width columns.
warning: Invalid argument supplied for foreach() in /home/thesubc/public_html/site/modules/mysite/plugins/layouts/columns.php on line 30.
-----------------------------------------
Basic layout
A single-column display of your personal content: No error
-----------------------------------------
Stacked two column
One main area and two equal-width columns:
warning: Invalid argument supplied for foreach() in /home/thesubc/public_html/site/modules/mysite/plugins/layouts/stacks.php on line 35.
warning: Invalid argument supplied for foreach() in /home/thesubc/public_html/site/modules/mysite/plugins/layouts/stacks.php on line 35.
----------------------------------------
Three Column
Three equal-width columns:
warning: Invalid argument supplied for foreach() in /home/thesubc/public_html/site/modules/mysite/plugins/layouts/triple.php on line 30.
warning: Invalid argument supplied for foreach() in /home/thesubc/public_html/site/modules/mysite/plugins/layouts/triple.php on line 30.
----------------------------------------
anything else you need let me know....

agentrickard’s picture

Hm. And you're running the most recent release?

Will test.

agentrickard’s picture

IS the default content set empty?

agentrickard’s picture

Status: Active » Postponed (maintainer needs more info)

Cannot confirm. See http://therickards.com/mysite/Bappsack for example.

This error occurs when an empty content array is accidentally passed to the layout files. The update to 5.x.2.11 should fix this.

tsavino’s picture

Thats what the problem was a empty content array
Thanks for the help
Tom
http://www.thesubculture.com/

agentrickard’s picture

Right, but there are safeguards that should prevent that error from being printed, so I'm still concerned.

If there is an empty content array, the code is supposed to handle it gracefully.

tsavino’s picture

Here is the error on another site I have

http://www.iamharmony.com/spirit/mysite/37/view

I only seem to happen when your not logged in, when I am logged in I do not get this error...

agentrickard’s picture

I simply cannot replicate this error. See http://therickards.com/mysite/agentrickard

The 5.x.2.11 release was supposed to fix this problem. So please make sure you've updated to the latest version.

If you are on the latest version, I will need more information about user 37's data. A screenshot of the Content page would help (http://www.iamharmony.com/spirit/mysite/37/content).

The problem, which the cose described above should fix, is that you may have a multicolumn page with an empty column. If the columns aren't collapsed correctly, you get the invalid error.

tsavino’s picture

StatusFileSize
new75.14 KB

The verison I am using:
----------------------------------------
; $Id: mysite.info,v 1.4 2007/06/18 23:50:54 dww Exp $
name = MySite
description = Allows users to create a custom page of site content.
package = MySite
; Information added by drupal.org packaging script on 2007-09-02
version = "5.x-2.11"
project = "mysite"
datestamp = "1188742810"
-----------------------------------------
The picture that is attached is the content when logged in.

agentrickard’s picture

Status: Postponed (maintainer needs more info) » Active

I'm finally seeing this error on another site, where they gave me admin access.

Do you have any Locked Content in the default content set?

agentrickard’s picture

Scratch that, locked content does not seem to be relevant.

agentrickard’s picture

StatusFileSize
new65.48 KB

OK, I have managed to replicate this, but can you confirm:

This happens when the Default Settings are multi-region, but one of the regions is empty. See attached.

I should be able to fix this tonight.

agentrickard’s picture

Status: Active » Needs review
StatusFileSize
new1.69 KB

OK, I got it. If one of the regions is empty, right now we only fill it with content if yopu have certain permissions.

The attached patch corrects this behavior.

What I need from everyone is this:

The empty array should probably be replaced by a graceful theme function. What should that theme function present to the user?

agentrickard’s picture

This has been committed to HEAD and to 5--2 branch. When we have a good theme function, I'll roll a new release.

agentrickard’s picture

StatusFileSize
new43.36 KB

For reference, here's what happens now when the region is empty.

agentrickard’s picture

Status: Needs review » Closed (fixed)

This has been released as-is in 5.x.2.12. Sorry no one stepped up to help.