For instance, we want the 'book page' token type to extend the 'menu item' token type, but also add its own 'bid' token that does not apply to all menu links.

CommentFileSizeAuthor
#2 975112-token-extend-types.patch7.84 KBDave Reid
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Active » Needs review

Think I've actually got this. I thought I'd have to do a whole bunch of token type dependency parsing and graphing, but I don't think that it's likely we'll have a two-deep token type dependency. If so, I have some code ready for that.

Dave Reid’s picture

Dave Reid’s picture

Sweet!!! Committing #2 to CVS!
http://drupal.org/cvs?commit=466256

The example we provide is we want [current-user:ip-address] to return the IP address of the current logged-in user, but [user:ip-address] should not be provided as we have no idea what a single user's IP address is.

If ever this needs to resolve two levels of token type dependencies, here's the code I had started writing:

function _token_build_type_dependencies($token_types) {
  $graph = array();
  require_once DRUPAL_ROOT . '/includes/graph.inc';
  foreach ($token_types as $token_type => $token_type_info) {
    $graph[$token_type]['edges'] = array();
    if (isset($token_type_info['type']) && $token_type_info['type'] != $token_type) {
      $graph[$token_type]['edges'][$token_type_info['type']] = 1;
    }
  }
  drupal_depth_first_search($graph);
  foreach ($graph as $token_type => $data) {
    $token_types[$token_type]['weight'] = $data['weight'];
  }
  return $token_types;
}

      $dependent_token_types = _token_build_type_dependencies($token_info['types']);
      uasort($dependent_token_types, 'drupal_sort_weight');
      $dependent_token_types = array_reverse($dependent_token_types, TRUE);
sbrattla’s picture

Just wanted to follow up on this one, as I believe it is closely related to something I've run into.

I've defined a token 'sender' in my hook_token_info() the following way:

  $types['sender'] = array(
    'name' => t('Sender'),
    'description' => t('Tokens related to the sender of an e-mail.'),
    'type' => 'user',
  );

What I would expect is that the 'sender' extends 'user', so that all tokens available for a 'user' is available for a 'sender'. When I open up a token browser, this proves to be correct. All tokens which would be available for a 'user' is listed as available for a 'sender'.

However, it seems to stop with that. Tokens available for a 'user' appears to be available for a 'sender' as well (as the token browser says so), but no [sender:X] token is being replaced at all.

I'm uncertain if my issue is related to this issue?

Chris Matthews’s picture

Issue summary: View changes
Status: Needs review » Fixed

The patch in #2 was committed 8 years ago so changing the issue status to fixed.

Status: Fixed » Closed (fixed)

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