Now that #484340: Token support is taken care of, there is likely to be a surge of demand for additional CTools context keywords. There are very similar to tokens, but token.module didn't work for this (though the new line of token stuff that eaton is working on *will* be compatible with this and may eventually replace the existing system, that can't happen just yet).

Using hook_ctools_context_convert_list() and hook_ctools_context_converter_alter() it should be fairly easy to add context keywords for CCK fields. Especially since the contexts can be restricted to a type or set of types in most cases. I haven't tested this system out, but I meant it in particular for CCK and things like it that add fields to nodes.

I'm not sure if I'll have the chance to work up a patch myself.

Comments

markus_petrux’s picture

I just tried to figure out by looking at CTools code (latest dev). Please, correct me if I'm wrong.

Is this prototype correct? Please, see @todo comments.

/**
 * Implementation of hook_ctools_context_convert_list().
 */
function content_ctools_context_convert_list($plugin, &$converters) {
  // Add items to $converters array as 'key' => t('Label').

  // @todo: How do we know we can expose converters for the given plugin?
}

/**
 * Implementation of hook_ctools_context_converter_alter().
 */
function content_ctools_context_converter_alter($context, $converter, &$value) {
  // Make sure we have a node to extract fields data from.
  if ($context->type != 'node' || empty($context->data)) {
    return;
  }

  // Get a shortcut to the node.
  $node = $context->data;

  // Alter $value using $converter for the given node $context.
  // Leave $value unchanged if we do not support this converter.

  // @todo: May we reuse current CCK tokens integration stuff or should we dup (probably) based on that?
}
markus_petrux’s picture

Status: Active » Postponed

Well, it seems we could wait a little until token for D7 is committed, backported to token 2.x for D6, and then it seems CTools could take the food from there. Will see... meanwhile, I think we can mark this issue as "postponed".

For reference:
- #484340: token support (comments #8 to #12) (CTools issue)
- #113614: Add centralized token/placeholder substitution to core (D7 issue)

joshuajabbour’s picture

I'm not sure if there really are contexts or situations that tokens wouldn't work within, but ctools 6.x-1.7 has built-in support for node tokens. However, CCK field tokens were broken because ctools was only grabbing the first set of tokens (those provided for base node values). This patch fixes the issue and adds CCK fields into the node contexts: #943896: Context converters using token module limited to one set (omits CCK fields, etc).