2

I'm building a custom module to build some tokens. I have added hook_token_info() and it works great. I haved added hook_tokens(), but I'm not able to debug with var_dump() or with dpm().

function mymoduletoken_token_info() {
  $info['tokens']['node']['seccion'] = array(
    'name' => t('Seccion'),
    'description' => t('Custon token to add to the G.A. script more optoins in seccion'),
  );

  $info['tokens']['node']['subseccion'] = array(
    'name' => t('Subseccion'),
    'description' => t('Custon token to add to the G.A. script more options into subseccion'),
  );
  return $info;
}

function mymoduletoken_tokens($type, $tokens, array $data = array(), array $options = array()) {
  dpm($type);
  dpm($token);
  dpm($data);
  dpm($options);
}

I would like to debug the different options to build the token with the information I need.

3
  • If you add a hook implementation to an activated module, you have to clear the cache. Otherwise, Drupal will not know that your module implements a hook that it previously did not implement.
    – Oswald
    Jun 5, 2013 at 14:57
  • Thanks Oswald. But the question, how to make the dpm() to know the information I have in some urls to use with token. Jun 6, 2013 at 8:18
  • Ever considered xdebug?
    – Mołot
    Jun 6, 2013 at 11:05

1 Answer 1

6

I think I'm following you...you want a way to invoke the tokens you've created outside of their natural context, so you can debug easily? If so, you can use the token_replace() function. As you're defining tokens that need a node object, you'll have to load an appropriate one up for the job:

// Load the node.
$node = node_load($appropriate_nid);

// Prepare the text string.
$text = 'something involving [node:seccion]';

// Set up some options. Your mileage may vary here.
$options['sanitize'] = FALSE;

// Get the replacement text.
$replacement = token_replace($text, array('node' => $node), $options);

That will invoke your module's implementation of hook_tokens(), and the dpm() calls will fire.

If you're doing a lot of token development it might make sense to wrap that functionality in a simple form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.