After enabling CCK, Views and Panels 2.0 Alpha 7, I went and added a new panel. I added the "frontpage" view to the right column with the title "News" just to test out Alpha 7, and I got the following warnings:

* warning: natcasesort() [function.natcasesort]: The argument should be an array in C:\Apache2\htdocs\shared\sandbox\sites\all\modules\panels\panels.module on line 849.
* warning: Invalid argument supplied for foreach() in C:\Apache2\htdocs\shared\sandbox\sites\all\modules\panels\panels.module on line 850.
* warning: natcasesort() [function.natcasesort]: The argument should be an array in C:\Apache2\htdocs\shared\sandbox\sites\all\modules\panels\panels.module on line 849.
* warning: Invalid argument supplied for foreach() in C:\Apache2\htdocs\shared\sandbox\sites\all\modules\panels\panels.module on line 850.
* warning: natcasesort() [function.natcasesort]: The argument should be an array in C:\Apache2\htdocs\shared\sandbox\sites\all\modules\panels\panels.module on line 849.
* warning: Invalid argument supplied for foreach() in C:\Apache2\htdocs\shared\sandbox\sites\all\modules\panels\panels.module on line 850.

I'm not entirely sure what's going on here.

Comments

robloach’s picture

Could it be that the view had no content nodes in it when I created the panel? The panel still worked, I just got those strange warnings when creating it.

merlinofchaos’s picture

Interesting. That's the code that figures out the categories and indicates something is screwing up; that but shouldn't even be possible, since it's using data that's paired together just prior to the call. I've never seen anything like this, so I may need you to put in some debugging prior to that line to get an idea of what's happening.

IN fact, if you could do a dprint_r (or similar) of $titles and $weights just prior to the foreach that contains the natcasesort in panels.module and post the results here, that could be handy.

yoroy’s picture

I'm seeing the same warnings. On a fresh drupal 5.1 install, with Panels alpha7 being the only contrib module, on saving a first panels-page.
If this is about categories: there are none in this drupal install. Might that be a clue?

merlinofchaos’s picture

By categories, I mean the categories it uses to sort the possible content types in the add content plugin.

yoroy’s picture

Oh. I tried adding a print_r($weights) but then the add-content modal does not fully load (just the throbber staying there)

this is from panels.module, starting at line 848:

      $output .= '<div class="panels-section-decorator"></div>';
      natcasesort($titles[$category]);
      print_r ($weights);
      foreach ($titles[$category] as $id => $title) {
        $output .= $categories[$category][$id];
      }

I'm horrible with PHP, so I have to ask is that the place I should put it?

To be specific: I get the warnings when saving after I added content to the panel.

robloach’s picture

What if you did an is_array check before you pass it to natcasesort? I can't seem to replicate this error now....

merlinofchaos’s picture

yoroy: Try a drupal_set_message rather than a print_r. It can be difficult to get debug messages out of the modal. Here is what I do:

Open two tabs. On one tab, I open the modal; whenver it does an ajax call and a drupal_set_message gets called, I refresh the page in the other tab, and that shows me whatever got set.

I haven't seen this natcasesort bug come up again; I think I'd rather not 'fix' it the easy way by just defining an array as it should *never* be empty, and the fact that it is indicates a larger bug. Fixing the symptom could obscure a bigger problem.

yoroy’s picture

using two open tabs in firefox learned me:

- the warnings already occur on opening the modal: I click the add-content icon in the first tab, refresh the second tab: errors given.
- Next: add some content in the modal, click [add pane], modal closes. A refresh in the second firefox tab: no errors shown.

I did this in panels.module, line 849 - 852:

      natcasesort($titles[$category]);
      drupal_set_message();
      foreach ($titles[$category] as $id => $title) {
        $output .= $categories[$category][$id];

This give me no extra output rendered to the screen… I'm probably doing something wrong…

merlinofchaos’s picture

You need to put some kind of a message in drupal_set_message().

  drupal_set_message(var_export($titles, TRUE));

That'd be a good start.

yoroy’s picture

that works, this is the drupal_set_message output when opening the modal:

    * array ( 'Custom' => array ( 0 => 'Node content', 1 => 'New custom content', ), 'Core blocks' => array ( 0 => 'Recent comments', 1 => 'Syndicate', 2 => 'User login', 3 => 'Who\'s new', 4 => 'Who\'s online', ), 'Menus' => array ( 0 => 'Primary links', 1 => 'Navigation', ), )
    * array ( 'Custom' => array ( 1 => 'New custom content', 0 => 'Node content', ), 'Core blocks' => array ( 0 => 'Recent comments', 1 => 'Syndicate', 2 => 'User login', 3 => 'Who\'s new', 4 => 'Who\'s online', ), 'Menus' => array ( 0 => 'Primary links', 1 => 'Navigation', ), )
    * array ( 'Custom' => array ( 1 => 'New custom content', 0 => 'Node content', ), 'Core blocks' => array ( 0 => 'Recent comments', 1 => 'Syndicate', 2 => 'User login', 3 => 'Who\'s new', 4 => 'Who\'s online', ), 'Menus' => array ( 0 => 'Primary links', 1 => 'Navigation', ), )
    * array ( 'Custom' => array ( 1 => 'New custom content', 0 => 'Node content', ), 'Core blocks' => array ( 0 => 'Recent comments', 1 => 'Syndicate', 2 => 'User login', 3 => 'Who\'s new', 4 => 'Who\'s online', ), 'Menus' => array ( 1 => 'Navigation', 0 => 'Primary links', ), )
robloach’s picture

Version: 5.x-2.0-alpha7 » 5.x-2.0-alpha9

Hit it again with Alpha 9....

* warning: natcasesort() [function.natcasesort]: The argument should be an array in D:\xampp\htdocs\hotwiredstocks\sites\all\modules\panels\panels.module on line 1023.
* warning: Invalid argument supplied for foreach() in D:\xampp\htdocs\hotwiredstocks\sites\all\modules\panels\panels.module on line 1024.

merlinofchaos’s picture

Status: Active » Fixed

I've fixed the symptom, which is to say that this error message will not appear anymore; however, I don't know what's actually *causing* the bug, so there may well still be something wrong here.

Anonymous’s picture

Status: Fixed » Closed (fixed)