You create an array for the token_replace_multiple() function that includes the $node parameter that you just loaded. The problem is that you always add the node even if it doesn't exist.

I get errors in the token, pathauto and other modules because of this small mistake.

What I suggest is that you add the $node parameter to the array only if the node was loaded. (see patch)

I specifically see the problem on a page created from a view, i.e. not a node and not a page that was added to a menu either.

Thank you.
Alexis Wilke

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hass’s picture

Dave have reviewed this code... What token version are you using and how can I repro this? I have never seen any warnings myself... What abou D7?

AlexisWilke’s picture

I don't use D7. 8-}

This only happens on pages that are not nodes (i.e. a view).

I have E_ALL turned ON as well to see all E_NOTICE errors, but the problem is that the hook_token_values() using the type 'node' can be overwritten by many and all expect a valid $node... Some other processes also generate an error (i.e. pathauto.)

If you want to get the error every time, use NULL instead of $node, then in token you get an error here:

function node_token_values($type, $object = NULL, $options = array()) {
  $values = array();
  switch ($type) {
    case 'node':
      $node = $object;
      // ERROR: $node->uid fails since $node is NULL or FALSE
      $account = db_fetch_object(db_query("SELECT name, mail FROM {users} WHERE uid = %d", $node->uid));

By changing your code with my patch, I avoid the problem by not putting the $node in the array when it does not represent a valid node (i.e. on a view.)

Thank you.
Alexis

hass’s picture

Yeah, but D7 comes very first... Than a backport...

AlexisWilke’s picture

That's up to you... You already got the fix for D6 though.

Oh and 114k users for D6 versus 6k for D7. But I guess that doesn't count since that's 114k happy customers. 8-)

hass’s picture

Version: 6.x-3.x-dev » 7.x-1.x-dev
Status: Needs review » Needs work

I guess you are familiar with the process to prevent regressions... :-)

hass’s picture

Title: Misuse of token_replace_multiple() » E_ALL: Node object could be empty
Status: Needs work » Fixed

Committed to D6 and changed version committed to D7.

Status: Fixed » Closed (fixed)

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