1

I've created module with hook_token_info() and hook_tokens(). Now i can see my token in list of all availble tokens:

$ drush token | grep customtoken
 node        customtoken         Node related token

But this token is not available in rules action 'Set a data value'. What is the problem with custom token?

My rule looks like:

  1. Events: 'After saving new content', 'After updating existing content'
  2. Conditions: 'Content is of type'
  3. Action: 'Set a data value'

1 Answer 1

-2

1) The easy, but dirty way:

You can nest your tokens in an existing type (see http://drupal.org/node/1714418#comment-6468184). Eg, in hook_token_info() do:

  return array(
    'types' => $types,
    'tokens' => array(
      'site' => $my_tokens,
    ),  
  );

Your tokens will appear under "Site information"

2) The harder, but cleaner way:

Define your own rules data type with hook_rules_data_info()

function mymodule_data_info() {
  return array(
    'vub_events_data' => array(
      'label' => t('My Module Data'),
      'group' => t('My Module'),
      'token type' => 'my_module',
      'property info' => array(),
    ),
  );
}

and use this in your hook_token_info() implementation.

2
  • Hello, Bram, thank you for your answer. First way is not working for me. If you look on my first post you will see that token was added to standard type 'node', of course i've attempted 'site' too. Second way is not good because more complicated than custom token only :) Thank you once more, I abandoned the token and chose a different solution. Commented Mar 17, 2013 at 10:11
  • Was not able to add a custom group of Tokens to the Rules UI with this answer. Believe there is a type-o in the function name, should be: MYMODULE_rules_data_info(). Are you suppose to use the data namespace in the token definition? In your example meaning: 'type' => 'vub_events_data',
    – doublejosh
    Commented Jul 30, 2014 at 19:51

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.