There is a problem with the return value of the token_info hook. First, it's not documented properly as this is a hook and it should state this fact in the comment above the function according to the Drupal Standards model. Second, it returns an associative array of arrays which is incorrect. The hook expects a non-associative array, not an associative array.

This issue can be viewed if you click "Flush all Caches" whenever this module is enabled. You will only see these errors when you flush all caches since it's rebuilding the hook cache when you do so. Once cache is cleared, the error does not show up anymore. Here are the errors you will see:

Warning: strnatcmp() expects parameter 2 to be string, array given in token_asort_tokens() (line 575 of modules/token/token.module).
Warning: strnatcmp() expects parameter 2 to be string, array given in token_asort_tokens() (line 575 of modules/token/token.module).
Warning: uasort(): Array was modified by the user comparison function in token_get_info() (line 533 of modules/token/token.module).

The following:

return array(
    'types' => array('user' => $type),
    'tokens' => array('user' => $user),
  );

Should be changed to:

return array(
    'types' => array($type),
    'tokens' => array($user),
  );

I'm sure this is causing problems somewhere since the return values are invalid.

Comments

pfaocle’s picture

Assigned: Unassigned » pfaocle

  • 8573f0c committed on 7.x-1.x
    Issue #2293595: correctly document Token hook implementations.
    
pfaocle’s picture

Thanks for this - I've documented the two Token hooks correctly (8573f0c).

However, I'm not able to see this issue my end and according to the hook documentation, what we currently have should be correct.

pfaocle’s picture

Ah, think I've got it - this only manifested itself for me when pathauto is also enabled. I don't think we need to (re-)declare the token type for "Users". See attached patch for testing - I'll commit this soon.

pfaocle’s picture

I'm committing this, as the Users token group is actually already defined by core's User module. Would appreciate some testing from those experiencing this issue or #804464: Warning message (warning: uksort(): Array was modified...)

  • 41457df committed on 7.x-1.x
    Issue #2293595: Don't define the Users token group, as core User module...
pfaocle’s picture

Assigned: pfaocle » Unassigned
Status: Active » Needs review
bmateus’s picture

I'm having the same exact error, but the Role Weights module is not even installed...
The Role Weights might not be the culprit here.

pfaocle’s picture

Status: Needs review » Fixed
pfaocle’s picture

Assigned: Unassigned » pfaocle

Status: Fixed » Closed (fixed)

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