Commit dd14aa97 authored by merlinofchaos's avatar merlinofchaos

Issue #943896 by ayalon: Fix CCK and tokens.

parent 89b3b8f7
......@@ -170,8 +170,15 @@ function ctools_context_node_convert_list() {
'type' => t('Node type'),
);
// Include tokens provided by token.module.
if (module_exists('token')) {
$list += reset(token_get_list(array('node')));
foreach (token_get_list(array('node')) as $tokens) {
$readabletokens = array();
foreach($tokens as $fieldname => $desc) {
$readabletokens[$fieldname] = $fieldname . ': ' . $desc;
}
$list += $readabletokens;
}
}
return $list;
......@@ -193,9 +200,12 @@ function ctools_context_node_convert($context, $type) {
case 'type':
return $context->data->type;
}
// Check if token.module can provide the replacement.
if (module_exists('token')) {
$values = token_get_values('node', $context->data);
if ($key = array_search($type, $values->tokens)) {
$key = array_search($type, $values->tokens);
if ($key !== FALSE) {
return $values->values[$key];
}
}
......
......@@ -31,16 +31,19 @@ function ctools_context_create_token($empty, $data = NULL, $conf = FALSE) {
* Implementation of hook_ctools_context_convert_list().
*/
function ctools_context_token_convert_list() {
// Pass everything through to token_get_list().
return reset(token_get_list(array('global')));
$list = array();
foreach (token_get_list(array('global')) as $tokens) {
$list += $tokens;
}
return $list;
}
/**
* Implementation of hook_ctools_context_converter_alter().
*/
function ctools_context_token_convert($context, $token) {
$values = token_get_values();
$key = array_search($token, $values->tokens);
function ctools_context_token_convert($context, $type) {
$values = token_get_values('global');
$key = array_search($type, $values->tokens);
if ($key !== FALSE) {
return $values->values[$key];
}
......
......@@ -148,9 +148,14 @@ function ctools_context_user_convert_list() {
'uid' => t('User ID'),
'name' => t('User name'),
);
// Include tokens provided by token.module.
if (module_exists('token')) {
$list += reset(token_get_list(array('user')));
foreach (token_get_list(array('user')) as $tokens) {
$list += $tokens;
}
}
return $list;
}
......@@ -164,9 +169,12 @@ function ctools_context_user_convert($context, $type) {
case 'name':
return $context->data->name;
}
// Check if token.module can provide the replacement.
if (module_exists('token')) {
$values = token_get_values('user', $context->data);
if ($key = array_search($type, $values->tokens)) {
$key = array_search($type, $values->tokens);
if ($key !== FALSE) {
return $values->values[$key];
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment