On my site: http://www.pennsylvaniabeaglegundogassociation.org/home , there is a content type called beagle club that contains information on various clubs. When the drupal site was first set up in July, I created numerous clubs and had no problem editing them. About two weeks ago (I've been busy with other things) I received an email that the club's content could no longer be editied. Instead when the edit button was pressed the following message came up:

Fatal error: [] operator not supported for strings in /home/beagle5/public_html/pennsylvaniabeaglegundogassociation.org/includes/menu.inc on line 1866

Not modules were added between when the club editing worked as expected and when it stopped. An additional club was added sometime in between by another authorized user but editing worked after that add.

This is the line of code referenced by the error (which seems correct although I am not strong with PHP):
$l['attributes']['class'][] = 'active-trail';

Which is in the function menu_navigation_links

I was not sure whether to post this to the core errors or a specific module so I figured I would start here.

The error first appeared with 7.28 (which is the initial version installed on the server). I have since upgraded to 7.31 and there has been no improvement.

Any help is greatly appreciated. I can provide other information if necessary.

Comments

nevets’s picture

Have you tried clearing cache?

The message suggests $l['attributes']['class'] is set to a string when it should be an array.

I would temporarily change

$l['attributes']['class'][] = 'active-trail';

to

if ( is_array($l['attributes']['class']) ) {
  $l['attributes']['class'][] = 'active-trail';
}
else {
  drupal_set_message("Bad menu link?<pre>" . print_r($l, TRUE) . '</pre>');
}

it may help to localize the source of the problem.

JC4131a’s picture

I love you.

I can now get to the edit. I think the problem is still there. Here's the message:

Array
(
[attributes] => Array
(
[title] => The 31 Beagle Clubs across the Commonwealth of Pennsylvania
[class] => target-blank
)

[href] =>
[title] => Clubs
)

Doesn't this imply that its an array though? Which is how the code looked so now I'm really confused. Again, PHP is not my forte.

nevets’s picture

The line

[class] => target-blank

tells use 'class' is a string otherwise it would read

[class] => Array ....

To add to Japan's comment below, you need to find the code that is adding 'target-blank'.

Jaypan’s picture

Somewhere in your code, whether it's something you've custom coded, or a contributed module has done this:

<?php
$some_element
['#attributes']['class'] = 'something';
?>

When they needed to do this:

<?php
$some_element
['#attributes']['class'][] = 'something';
// Or
$some_element['#attributes']['class'] = array('something');
?>

You'll need to track down where this is happening. You could start with looking in your theme, in template.php, to see if there is an implementation of THEMENAME_menu_link().

I will soon be leaving the Drupal forums permanently. To understand why, please see this thread.

JC4131a’s picture

Thanks again for the help.

I have a question before I go too crazy. I greped for instances of target-blank over my directory and only files contained in a module menu_target came up. Seeing as how I don't use that module, I uninstalled from the menu and then deleted the files through ftp. The same message persisted, indicating that ['attributes']['class'] was still a string for those content items. Since the code I believe was causing the problem was removed I added the line $l['attributes']['class'] = array(); underneath drupal_set_message("Bad menu link?<pre>" . print_r($l, TRUE) . '</pre>'); with the assumption that those "corrupted" lines are not being used for their original intent anymore so I can just set them to empty arrays and all should be good. To my dismay, the message is still popping up after entering pages more than once. This makes me think that I was wrong to presume menu_target as the culprit and that code somewhere else is causing the issue. Dose this seem correct? I am asking in the hopes that I have a misconception on php and that there is some other code I should write to achieve what I am trying.

If everything above seems correct and something else is the culprit, I am assuming that grepping for "target" && "-blank" should find me any offending files since it could be that the string is being assembled in parts from different sections of code. An affirmative to my assumptions or recommendations as to where I am going wrong is much appreciated.

nevets’s picture

I would grep just for target and if there is too many pipe that grep to a second one that looks for 'blank'.

JC4131a’s picture

I went for target and I can find things like this:

links['top']['edit_custom_content'] = array(
      'title' => t('Edit custom content pane'),
      'href' => url('admin/structure/ctools-content/list/' . $name_of_pane . '/edit', array('absolute' => TRUE)),
      'attributes' => array('target' => array('_blank')),
    );

But this seems correct to me and not the source of the problem. Everything else was either html code with php embedded and no references to class or attribute arrays OR it set class to a variable/string that did not contain references to about or blank.

JC4131a’s picture

After more grepping, I have not found any files in the modules that I have installed that modify an array element 'class' and set it to a string that would only include about and/or blank.

Any ideas?

I can just keep the if statement and drop the message display and everything is working but I have concerns about that solution coming back to haunt me, especially since I will need to include the command every time I update the core.

Jaypan’s picture

Maybe try a debug_backtrace() right before the error. This will give you a call of the function stack that led to that point - maybe you can look through the various functions to see if one of them is setting this class.

Your other option is to try another theme and see if the problem goes away, and if it doesn't, start disabling modules one by one until you find the problem.

I will soon be leaving the Drupal forums permanently. To understand why, please see this thread.

JC4131a’s picture

The back trace was just core functions going up to drupal_deliver_page and above it was menu_execute_active_handler from index.php.

I disabled all themes other than seven and stark and all modules other than core modules. No luck.

Just to double check

if ( is_array($l['attributes']['class']) ) {
            $l['attributes']['class'][] = 'active-trail';//keep outside of if         
        }
        else {
           
            drupal_set_message("Bad menu link?<pre>" . print_r($l, TRUE) . '</pre>');// delete if is_array and else
            $l['attributes']['class'] = array();
        }

should fix the problem if nothing else was resetting the 'class' key to point to a string again, correct?

Right now I'm just using the error message to verify if it did or did not work. So far it continues to appear after a click, back, click again to edit a content item.