Maybe a bug? ogactivity.module : "Catchable fatal error"

dman - June 24, 2009 - 09:42
Project:Activity
Version:5.x-2.1-2
Component:Activity Contrib
Category:bug report
Priority:normal
Assigned:Unassigned
Status:won't fix
Description

Catchable fatal error: Object of class stdClass could not be converted to string in .../modules/token/token.module on line 190

Sorry, no patch - I'm remoted into a foreign system that's decided to use SVN instead ... :-(

Anyway, the existing code below:

<?php
function ogactivity_token_values($type, $data = NULL, $options = array()) {
  static
$authors;
  if (
$type == 'ogactivity' && !empty($data)) {
    if (!isset(
$authors[$data['author-uid']])) {
     
$user = db_fetch_object(db_query('SELECT uid, name FROM {users} WHERE uid = %d'$data['author-uid']));
     
$authors[$data['author-uid']] = theme('username', $user);
    }
   
$data['author-name'] = $authors[$data['author-uid']];
  }
  return
$data;
}
?>

... will return a full $node object as the token value when token_get_values() invokes module_invoke_all('token_values', 'node', $node);
... this results is a horrible $node object in the list of strings.
I modified it to :
<?php
function ogactivity_token_values($type, $data = NULL, $options = array()) {
  static
$authors;
  if (
$type == 'ogactivity' && !empty($data)) {
    if (!isset(
$authors[$data['author-uid']])) {
     
$user = db_fetch_object(db_query('SELECT uid, name FROM {users} WHERE uid = %d'$data['author-uid']));
     
$authors[$data['author-uid']] = theme('username', $user);
    }
   
$data['author-name'] = $authors[$data['author-uid']];
    return
$data;
  }
}
?>

... shifting the return into the case where there actually is something to return.

... Sorry, I can't actually figure what version this is on (not my site, just troubleshooting). Something in Drupal 5.
$Id: token.module,v 1.5.2.12 2008/01/17 10:46:16 greggles Exp $
. Huh. That's old. Feel free to ignore it, looks like it can't have been bothering anyone else for a year. Or it's fixed in one of the various dev versions.
Maybe it only shows up with strict warnings.

#1

sirkitree - July 1, 2009 - 02:16
Status:active» postponed (maintainer needs more info)

#2

dman - July 1, 2009 - 02:30

HOOK_token_values() must return array of strings (the token values).
As it stands, if $type does NOT = 'ogactivity' , if $type = 'node' , then ogactivity_token_values returns a $node object instead!
This ruins the $token array and triggers casting errors in later token processing.

#3

sirkitree - November 4, 2009 - 05:45
Status:postponed (maintainer needs more info)» won't fix

5.x unsupported please see 6.x-2

 
 

Drupal is a registered trademark of Dries Buytaert.