the Token module has been spewing these errors lately.

strnatcmp() expects parameter 2 to be string, array given in token.module at line 464 in token_asort_tokens()

I finally got a chance to look into this, and it looks like workflow's sending malformed tokens over to the Token module. Here's an example of a good one and one that Workflow sends.

Good one:

array (
  'name' => 'Private message',
  'description' => 'Tokens related to private messages.',
  'needs-data' => 'privatemsg_message',
  'type' => 'privatemsg_message',
)

From workflow:

array (
  'name' => 
  array (
    0 => 'Nodes',
    1 => 'Workflows',
  ),
  'description' => 
  array (
    0 => 'Tokens related to individual content items, or "nodes".',
    1 => 'Tokens related to workflows.',
  ),
  'needs-data' => 
  array (
    0 => 'node',
    1 => 'node',
  ),
  'type' => 'node',
)

Now that I know what's causing the error, I'll go cook up a patch for this.

CommentFileSizeAuthor
#5 1364162-malformed_token.patch409 bytesOgredude

Comments

Ogredude’s picture

Status: Active » Closed (cannot reproduce)

I can't figure out where this malformed array is coming from.

workflow_token_info() is absolutely correct.

I got the error to go away for a bit by doing
drush ev "token_clear_cache();"

but the issue returned a very short time later.

Ogredude’s picture

Assigned: Ogredude » Unassigned
Status: Closed (cannot reproduce) » Active
Anonymous’s picture

I'm also getting this on a multilingual site:

Warning: htmlspecialchars() expects parameter 1 to be string, array given check_plain()... /includes/bootstrap.inc line 1521).

Shouldn't workflow_token_info() return a non-nested $type? #735354: User token types should *not* be nested.

<?php
/**
 * Implements hook_token_info().
 */
function workflow_token_info() {
...
  return array(
    'types' => $type,
    'tokens' => array('node' => $tokens),
  );

}
?>
Anonymous’s picture

But if I change array('node' => $type) to $type it triggers a warning on the status report page:

The following tokens or token types are not defined as arrays:

$info['types']['name']
$info['types']['description']
$info['types']['needs-data']

Ogredude’s picture

Status: Active » Needs review
StatusFileSize
new409 bytes

I think I found the source of the issue. Workflow was putting its tokens into the 'node' namespace. Changed it to put them in the 'workflow' namespace instead.

Anonymous’s picture

Thanks for making a patch, I don't have git on my sytem.

FYI, I also had to change workflow_tokens() and include square brackets in the array indices, otherwise I got an extra bracket around my replacements:

          $values['[workflow:workflow-current-state-name]']                =  $sid->state; // @edith
          $values['workflow:workflow-old-state-name']                    =  $old_sid->state;
          $values['workflow:workflow-current-state-date-iso']            =  date('Ymdhis', $date);
          $values['workflow:workflow-current-state-date-tstamp']         =  $date;
          $values['workflow:workflow-current-state-date-formatted']      =  date('M d, Y h:i:s', $date);
          $values['workflow:workflow-current-state-updating-user-name']  = check_plain($user_name);
          $values['workflow:workflow-current-state-updating-user-uid']   = $uid;
          $values['workflow:workflow-current-state-updating-user-mail']  = check_plain($mail);
          $values['[workflow:workflow-current-state-log-entry]']           = filter_xss($comment, array('a', 'em', 'strong'));
Bastlynn’s picture

Status: Needs review » Closed (fixed)

@Ogredude - patch looks good, I've pulled it over into the dev branch. Thanks for the contrib :)

@Edith - I'm not sure that's a solution that will work on the module. I'm very curious how the double-brackets are getting introduced to your system. I don't think that's coming from workflow, especially since it's just those two values you're seeing it for. I think that needs a closer look in wherever you're calling the token from, perhaps the calling system is passing in [[workflow-current-state-name]] which is how the double bracket is getting in there? It also looks like your code is changing the token names by adding workflow: to the front of each name.