AJAX calls are returning 500 errors, for example, when clicking "Customize this page" or "Change layout" on a Panels page.

This is from my server log:

PHP Fatal error: Unsupported operand types in sites/all/modules/contrib/ctools/plugins/content_types/token/token.inc on line 42,

This is the line in question:
$token += array('description' => '');

$token must be an array by the time this line executes, so I'm not sure what the error's about, but I worked around it like this:

//$token += array('description' => '');
$token['description'] = '';

This is a new problem; the Panels features had previously worked for me. I just upgraded Token to 7.x-1.1. Could that be a factor?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

That would indicate that somehow $token is not actually an array at that point.

rohnjeynolds’s picture

Sorry for the delayed reply, and for leaving out an important detail: Line 41 is:
if (!empty($token['name'])) {
That's why I was assuming $token must be an array by the time it gets to line 42.

AaronBauman’s picture

Category: bug » support

$token['name'] is not empty if $token is a string.

I ran into the same error after installing a D7 module that implemented hook_token_info, but did not return the correct format.
(In my case a module was upgraded from D6, where these values for hook_token_list were all strings.)

This debugging patch should let you know the culprit, which you can then fix or report appropriately
(be sure to enable devel module first):

--- ctools/plugins/content_types/token/token.inc	(revision 1389)
+++ ctools/plugins/content_types/token/token.inc	(working copy)
@@ -39,6 +39,10 @@
   foreach ($info['tokens'] as $entity_type => $tokens) {
     foreach ($tokens as $name => $token) {
       if (!empty($token['name'])) {
+        if (!is_array($token)) {
+          dpm($token);
+          $token = array();
+        }
         $token += array('description' => '');
         $types[$entity_type . ':' . $name] = array(
           'category' => t('@entity (tokens)', array('@entity' => ucfirst($entity_type))),
quicksketch’s picture

I ran into the same error after installing a D7 module that implemented hook_token_info, but did not return the correct format.

Confirmed, this was the problem for me too. Thanks @aaronbauman.

Kartagis’s picture

I get the same error when I try to add flexible panel layout at http://dev-7.ozses.net/tr/admin/structure/panels/layouts/add-flexible

Kartagis’s picture

Version: 7.x-1.0 » 7.x-1.3

The issue persists.

Kartagis’s picture

Category: support » bug
merlinofchaos’s picture

This is going to require someone who is getting this problem to help out with the debugging and figure out what $token *is* at that point, and maybe figure out what's breaking it.

Kartagis’s picture

How can we debug? I'm guessing dpm won't work because I immediately get a 500. Maybe dd?

EclipseGc’s picture

You can do what #3 illustrates. This will give the dpm value of $token before the error and set token to something that can get past the error as well.

If you are having this error, can you confirm/deny whether you are using flexible layouts?

Eclipse

EclipseGc’s picture

Status: Active » Postponed (maintainer needs more info)

Changing the status on this. We need people who are getting this problem to actively help us debug it.

Eclipse

EclipseGc’s picture

Issue summary: View changes

Removed information about my server and path from the issue

Deciphered’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
Priority: Critical » Major
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs review
FileSize
669 bytes

So I had this same issue, my cause was a not so great Contrib module that I won't get into.

The issue is that $token is a string where it should be an array, and CTools is doing a check (!empty($token['name'])) that logically should be failing, but isn't. To fix the issue, we simply need to add another conditional of is_array($token).

Patch attached.

realityloop’s picture

Status: Needs review » Reviewed & tested by the community

Works as advertised

realityloop’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
722 bytes

previous patch fails against 1.4, patch reroll against head

PhilY’s picture

sorry, useless comment.

dooug’s picture

This seems like a work-around when the bug is actually in other custom or contrib modules that aren't returning the proper format from hook_token_info. According to previous comments:

#3

I ran into the same error after installing a D7 module that implemented hook_token_info, but did not return the correct format.

#12:

So I had this same issue, my cause was a not so great Contrib module that I won't get into.

So it seems this patch shouldn't be necessary, but rather the issues should be filed against those other contrib modules, though they haven't been mentioned by name. Which modules cause this bug?

Deciphered’s picture

Maybe so, but it's never a bad thing to ensure the data we are about to process is in the format it is expected to be, especially when it requires such a minor change.

However, I too dislike bandaid fixes, especially when the real issue never gets resolved, so maybe the solution is to implement this fix as well as some form of Watchdog notice to let any developers paying attention know that X module is at fault and to please report the issue.

couloir007’s picture

Could this be a php 5.3 issue? I'm getting other oddities that appear to be a 5.3 vs 5.4 and higher issue.

Sean

Chris Matthews’s picture

The 5 year old patch to token.inc applied cleanly to the latest ctools 7.x-1.x-dev, but based on the previous comments this issue may need to be closed or postponed.