I'm trying to add "token support" to the cck "computed field" component.
For the moment, I've added the following HelloWorld code to the computed_field.module:
(as described in the API.txt from the token module)
/**
* Implementation of hook_token_list()
*/
function computed_field_token_list($type = 'all') {
if ($type == 'node' || $type == 'all') {
$tokens['node']['testtoken'] = 'list';
return $tokens;
}
}
/**
* Implementation of hook_token_values()
*/
function computed_field_token_values($type, $object = NULL) {
if ($type == 'node') {
$tokens['testtoken'] = 'value';
return $tokens;
}
}
But I'm getting the following error:
* warning: Invalid argument supplied for foreach() in /var/www/virtual/test.com/htdocs/modules/token/token_cck.inc on line 41.
* warning: Invalid argument supplied for foreach() in /var/www/virtual/test.com/htdocs/modules/token/token_cck.inc on line 41.
The token part works, as I can view it in my workflow, yet I'm puzzled why I'm getting these warnings. As I can see it's a way of walking thru the cck fields, and trying to add token support to them. But why didn't it work on the computed field in the first place?
Comments
Comment #1
jp.stacey commentedWhen those if statements aren't true, your functions won't return any definite value. Could token_cck be being confused by that? Maybe always return something, even if it's just an empty array:
(ps: if you surround the code you post here with <?php ... ?> then it gets syntax-highlighted!)
Comment #2
yched commentedThis support request is about token hooks, so it should be filed for Token.module
And jp.stacey is probably right, you should always return an array.
Comment #3
kvaes commentedthanks for the response (& for the ps!), will check into that
(didn't know where to post it, as it's an integration between different modules)
Comment #4
kvaes commentedThis prints the following:
Array ( [node] => Array ( [testtoken] => list ) ) Array ( [node] => Array ( [testtoken] => list ) )And gives the following errors:
Comment #5
jp.stacey commented@kvaes,
Sorry for the delay. I'm not familiar with the module, but could looking token_cck.module, line 40, your function
hook_token_listis being called with type 'field', not 'node' or 'all'. Then there are twoforeachloops over the returned value on line 42, but I think your functions will return aNULL.Try starting each function with
$tokens = array();, so that something iterable will always be returned. Do a dump of$sub_listin the token_cck.module file itself.Comment #6
clivesj commented@kvaes,
I also need Token support for my CCK computed fields.
Did you finalize the integration?
Could you post the code here?
Thank you.
Comment #7
clivesj commentedI PM'ed KVAES but other that a personal solution he doesn't have the token integration available.
Anyone who has a solution for token support of the computed field
Comment #8
karens commentedSee http://drupal.org/node/243775 for a solution (which needs to go into the Computed Field module).
Comment #9
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.