Token fails to validate in custom action

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
orbmantell's picture

I have two custom actions I am using on a site I am working on. The first action is based off the Rules Bonus Pack get argument from path, and it returns the argument. This action creates a token that I can access. I have checked and the token validates correctly when used in pre-defined actions.

The second action takes a numeric input and looks up an email address associated with that number. When I give it an interger it works correctly, however when I feed it the token created by my first action it errors because it treats the input as the raw string instead of evaluating the token.

Is there a way to tell my action to evaluate tokens on the configuration page? I have done a lot of searching on google and drupal.org, and the closest I can come was with token_replace(). When I try to use that function it returns the raw token string instead of the evaluated token.

My rule triggers on a form submission. The code follows:

<?php
// Implementation of hook_rules_action_info().

function extension_forms_approval_rules_action_info() {
  return array(
   
'extension_forms_approval_action_submitter_email' => array(
     
'label' => t('Load the form submitter\'s email'),
     
'arguments' => array(
       
'form_id' => array(
         
'type' => 'value',
         
'label' => t('Approve ID'),
        ),
      ),
     
'new variables' => array(
       
'submitter_email' => array(
         
'type' => 'value',
         
'label' => t('Form Submitter Email'),
        ),
      ),
     
'module' => 'Extension Forms Approval',
    ),
   
'extension_forms_approval_action_arg' => array(
     
'label' => t('Load path argument'),
     
'new variables' => array(
       
'arg_part' => array(
         
'type' => 'string',
         
'label' => t('Path argument'),
         
'save' => TRUE,
        ),
      ),
     
'module' => 'Extension Forms Approval',
    ),
  );
}



// Configuration form for 'extension_forms_approval_action_arg'.

function extension_forms_approval_action_arg_form($settings, &$form) {
 
$form['settings']['arg_part'] = array(
   
'#type' => 'select',
   
'#options' => range(0, 9),
   
'#default_value' => $settings['arg_part'],
   
'#title' => t('Part of path argument'),
   
'#description' => t('The part of the path argument to load. Note that
      numbering starts with zero.'
),
  );
}


// The 'extension_forms_approval_action_arg' action.

function extension_forms_approval_action_arg($settings) {
  return array(
   
'arg_part' => arg($settings['arg_part']),
  );
}



// Configuration form for 'extension_forms_approvalaction_submitter_email'.

function extension_forms_approval_action_submitter_email_form($settings, &$form, $variables) {
 
$form['settings']['approve_id'] = array(
   
'#type' => 'textfield',
   
'#default_value' => isset($settings['approve_id']) ? $settings['approve_id'] : '',
   
'#title' => t('Submitted form ID'),
   
'#description' => t('The ID of the submitted form.'),
  );
  return
$form;
}



// The 'extension_forms_approval_action_submitter_email' action.

function extension_forms_approval_action_submitter_email($form, &$form_state, $settings) {
 
$form_sid = $settings['#settings']['approve_id'];
  if (
is_numeric($form_sid)) {
   
$query = "SELECT <code>email</code> FROM <code>email_data</code> WHERE <code>user_id</code> = " . $form_sid;
   
$results = db_fetch_array(db_query($query));
   
$submitter_email = $results['data'];
  } else {
   
$submitter_email = '';
  } 
  return array(
'submitter_email' => $submitter_email);
}
?>

Thanks in advance for all help!

~orbmantell

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: