I am creating a custom rules event using hook_rules_event_info. This custom event is extending the features of the Stripe Subscription contrib module. The custom rules event is working fine so far.

Stripe Subscription creates several tokens for use within the module using hook_tokens. Is it possible for me to pass the tokens available in the module onto the custom rule event I have created so I can use them in the actions?

The event rule I have created looks like this:

function stripe_subscription_rules_event_info() {
  return array(
    'stripe_subscription_event' => array(
      'label' => t('A user subscribed'),
      'module' => 'stripe_subscription',
      'group' => 'Stripe Subscription',
      'variables' => array(
        'acting_user' => array('type' => 'user', 'label' => t('The user who is subscribing.')),
        'plan' => array('type' => 'text', 'label' => t('The purchased plan.')),
        'subscription_action' => array('type' => 'text', 'label' => t('The subscription acton')),
  • Have you come across this answer already drupal.stackexchange.com/a/110682/57183? Are you talking specifically about a "Set Data Value" type of Action? Cheers May 25, 2016 at 14:59
  • No I haven't come across this answer but it is not answering my particular question. I am trying to get the Stripe Subscription module tokens to appear in the Replacement Tokens list that appears in most of the rules actions, once it has been triggered by my custom event.
    – Ben
    May 25, 2016 at 15:58

1 Answer 1


When the Rule gets invoked, you can send any number of parameters along with it. Just make sure they match the expected data type.

rules_invoke_event('stripe_subscription_event', $acting_user, $plan, $stripe_subscription_event);

This will trigger the Rule and send the variables along. It is up to you call this function and obtain these values somehow.

Since your Rules description is A user subscribed, I suppose you should the submit function of that event to invoke the Rule. You might be able to grab the values from the $form_states['values'] array. I have no idea what the Stripe subscription module does, so I am not sure how you should obtain these values.

I don't think you can use tokens. Those are specifically for rendering content and I have never seen them used in code. (You might obtain the values by copying some of the logic though.)

  • Thanks Neograph734 for your answer. It makes sense to me that I can't just use the tokens from the module and have to pass them as variables into the custom event. I suppose I was hoping in some way that because I can pass a user id and get all the associated user tokens, I could somehow pass some kind of ID for the stripe module and get associated tokens. However, this is probably completely wrong as stripe subscriptions are not entities in the way that users are. Stripe subscription is a module that allows for recurring subscription payments using the stripe payment gateway.
    – Ben
    May 25, 2016 at 15:39
  • You can query the database for the id and obtain the associated values I guess. May 25, 2016 at 15:46
  • I have found out I can show all the subscription module tokens available by using the hook_rules_data_info() function and declaring the subscription token type that has already been declared using hook_tokens() in the module. However, I'm not sure what variable to pass for this when using rules_invoke_event().
    – Ben
    May 26, 2016 at 13:37

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.