RootCandy assumes the elements of the array retrieved from menu_navigation_links() are valid to pass to theme('item_list', ...). However, when RootCandy is set to display a tree of links other than the default, this array may contain subarrays of a type not expected by this function.

theme_item_list declares $items as "An array of items to be displayed in the list. If an item is a string, then it is used as is. If an item is an array, then the "data" element of the array is used as the contents of the list item. If an item is an array with a "children" element, those children are displayed in a nested list. All other elements are treated as attributes of the list item element.":
http://api.drupal.org/api/function/theme_item_list/6

The function treats the subarray as an attribute, i.e. a string, leading to the warning:
preg_match() expects parameter 2 to be string, array given in [...]/includes/bootstrap.inc on line 777
This may be the cause of problems reported at http://drupal.org/node/320145 and http://drupal.org/node/628902

Here is an example array (from primary links) that may cause the problem:

Array
(
    [menu-232] => Array
        (
            [attributes] => Array
                (
                    [title] => 
                )

            [href] => <front>
            [title] => Front
        )
...

The backtrace was:
bootstrap.inc: drupal_validate_utf8 line 741
common.inc: check_plain line 1526
theme.inc: drupal_attributes line 1499
theme.inc: call_user_func_array line 617
template.php: theme line 135
theme.inc: call_user_func_array line 617
template.php: theme line 128
page.tpl.php: _rootcandy_admin_navigation line 52
theme.inc: include line 1020
theme.inc: theme_render_template line 686
index.php: theme line 3

Comments

nyl_auster’s picture

Same probleme for me
In my case that was coming from the line 134, in the function root_candy_navigation()
That's to say from the function theme_item_list as said in the previous post.

Probably not a clean solution but i rewrite function in that way to remove the warning :

function rootcandy_admin_navigation($items, $class) {
  // remove sub array attributes
  foreach($items as $key => $item){
    unset($items[$key]['attributes']);
  }
  return theme('item_list', $items, NULL, 'ul', array('class' => $class));
}
thijsvdanker’s picture

I'm having the same problem when using a custom menu for certain roles.

sign’s picture

Version: 6.x-1.5 » 6.x-1.x-dev
Status: Active » Fixed

thanks guys for your reports

finaly got some time to fix this annoying issue.
added 3 lines to template.php

      if (!empty($item['attributes'])) {
        unset($item['attributes']);
      }

committed to dev version, thank you

Status: Fixed » Closed (fixed)

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

quiller’s picture

I'm not sure if this is relevant, but I was still seeing this issue with RootCandy 6.x-1.8 using Drupal 6.22. I followed the backtrace instructions from this comment and traced the errors back to line 119 of template.php.

I was able to eliminate the errors by changing the !empty() check to just empty():

  if (empty($item['attributes'])) {
    unset($item['attributes']);
  }

Since this is the exact opposite of the committed fix, I thought I'd mention it here and see if others are seeing something similar. I don't know if this is going to cause other side-effects, but so far I haven't noticed any issues. Anyway, it fixed my problem, so hopefully somebody that understands the details better can take it from here.

quiller’s picture

Status: Closed (fixed) » Active
sign’s picture

@quiller - what kind of errors were you getting? the same as above or some different?

sign’s picture

Status: Active » Fixed

I see, I have not released any version since the fix, so the fix is still sitting in the dev version.
Going to mark as fixed now, feel free to reopen once the 1.9 is out and the bug is still there.

Thanks

sign’s picture

Status: Fixed » Active
sign’s picture

Status: Active » Postponed (maintainer needs more info)

@quiller I will need to know what kind of errors were you getting from PHP.
Thanks!

quiller’s picture

I was getting errors similar to what's reported in this issue, e.g.:

preg_match() expects parameter 2 to be string, array given in [...]/includes/bootstrap.inc on line 777

I can revert the change I mentioned before and copy/paste the error verbatim if that would be useful.

Also, sorry for the lack of reply... I'm following the issue but didn't get any email notifications, so I might not have that configured correctly.

andrewc.swanson’s picture

Is the $item['attributes'] array needed at all at this point in the process? All necessary attributes are already pulled into $item['data'], $item['id'], and $item['class']. The additional attributes array seems superfluous. Unsetting the $item['attributes'] array, regardless of whether its empty, resolves the problem for me.