I have two custom actions. One of them provides a "text" variable and the other provides a "uri" variable.

Everything works fine after executing both actions if I use the data selector, but I have no replacement if I try to use them in direct input mode.

Since I want to send an email with both variables in the body I'm stuck with direct input mode.

What should I do? Should I implement token support of any kind?

Comments

e0ipso’s picture

These are my actions with provided variables:

/**
 * Implements hook_rules_action_info() on behalf of the user module.
 */
function email_downloadable_rules_action_info() {
  $defaults = array(
   'parameter' => array(
      'email' => array(
        'type' => 'text',
        'label' => t('Email'),
      ),
    ),
    'group' => t('Email downloadable'),
  );
  $items['email_downloadable_provide_code'] = $defaults + array(
    'label' => t('Provide the download code'),
    // 'base' => 'email_downloadable_provide_code',
    'provides' => array(
      'email_downloadable_code' => array(
        'type' => 'text',
        'label' => t('Download code'),
      ),
    ),
  );
  $items['email_downloadable_provide_link'] = $defaults + array(
    'label' => t('Provide the download link'),
    // 'base' => 'email_downloadable_provide_link',
    'provides' => array(
      'email_downloadable_link' => array(
        'type' => 'uri',
        'label' => t('Download link'),
      ),
    ),
  );
  $items['email_downloadable_provide_link']['parameter'] += array(
    'node' => array(
      'type' => 'node',
      'label' => t('Node'),
    ),
  );
  return $items;
}

And this is my test rule:

{ "rules_test" : {
    "LABEL" : "Prova Rules Email downloadable",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "email_downloadable", "rules" ],
    "ON" : [ "node_view" ],
    "DO" : [
      { "email_downloadable_provide_code" : {
          "USING" : { "email" : [ "site:current-user:mail" ] },
          "PROVIDE" : { "email_downloadable_code" : { "email_downloadable_code" : "Download code" } }
        }
      },
      { "email_downloadable_provide_link" : {
          "USING" : { "email" : [ "site:current-user:mail" ], "node" : [ "node" ] },
          "PROVIDE" : { "email_downloadable_link" : { "email_downloadable_link" : "Download link" } }
        }
      },
      { "drupal_message" : { "message" : "[email-downloadable-code]", "type" : "warning" } },
      { "drupal_message" : { "message" : "[email-downloadable-link]", "type" : "warning" } }
    ]
  }
}
e0ipso’s picture

Anyone else with this question?

Refineo’s picture

+1
how to use token variables in Rules properly ?

mradcliffe’s picture

It seems like the only way to do this is to fake an entity like in Entity API's system.info.inc, and use that as a type.

torotil’s picture

Status: Active » Closed (duplicate)

This is a duplicate of http://drupal.org/node/812058 .

e0ipso’s picture

Status: Closed (duplicate) » Active

As you may see the category from issue #812058 is task and the category for this issue is support request.

I do not need this feature to be integrated in Rules (although it would be cool), this means I need some directions on how to use Token, Entity Token (or whatever) to add token replacement support inside Rules for my custom variables.

Since the other issue has been opened for a year now, I think it is safe to state that a new way to come with a solution is needed.

I think both posters have the same problem, I'll give you that.

mitchell’s picture

Component: Provided Rules integration » Rules Core
Status: Active » Closed (duplicate)

Please test the patch in the other issue. I'm not trying to discourage your support request, just move things along.