Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
Maedi CreditAttribution: Maedi commentedComment #2
Dave ReidYou 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:
Comment #3
Maedi CreditAttribution: Maedi commentedCheers!