In a custom module I'm creating a token via the standard hook_token_info() and hook_tokens(). However in hook_token_info() the 'name' key in the $type array produces the following error:

Warning: htmlspecialchars() expects parameter 1 to be string, array given in htmlspecialchars() (line 1566 of /Applications/MAMP/htdocs/includes/bootstrap.inc). =>

Comment the line out and the warning goes away. Other modules use the same code and don't cause this warning. What am I doing wrong?

/**
* Implements hook_token_info().
*/
function my_module_token_info() {

  $type = array(
    'name' => t('My Module'),
    'description' => t('Tokens related to individual content items, or "nodes".'),
    'needs-data' => 'node',
  );

  $node['my-module'] = array(
    'name' => t("My Module"),
    'description' => t("..."),
  );

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

Comments

Maedi’s picture

Issue summary: View changes
Dave Reid’s picture

Status: Active » Fixed

You don't want to define the 'node' type again, that would be duplicating what node_token_info() does.

I think this is more what you want:

/**
* Implements hook_token_info().
*/
function my_module_token_info() {
  $info['tokens']['node']['my-module'] = array(
    'name' => t("My Module"),
    'description' => t("..."),
  );

  return $info;
}
Maedi’s picture

Cheers!

Status: Fixed » Closed (fixed)

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