Getting a custom field to appear correctly in Rules using entity form module I have written a custom field widget called foo which is inserted into an entity form to provide an autocomplete to another web service. I am trying to get the field data to be sent in an email via Rules. I am able to get the entityform tokens using List, text and the standard widgets to show in the email body and the list. However the form field defined in custom widget "foo" appears [entityform:field_foo] rather than [entityform:field-foo] which means that the send email rule in Rules appears to ignore it. 

From my understanding, I believe that I need to create declare a  token using hook_token_info():

function MYMODULE_token_info() {
  $info['types']['foo'] = array (
    'name' =&gt; t('Foo'),
    'description' =&gt; t('Tokens related to the foo widget'),
    'needs-data' =&gt; 'entityform'
  );
  $info['tokens']['foo']['organisation'] = array (
    'name' =&gt; t('Janet'),
    'description' =&gt; t('Custom foo widget field'),
    'type' =&gt; 'entityform'
  );
  return $info;
}


and then declare hook_tokens():

function MYMODULE_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  $sanitize = !empty($options['sanitize']);
  if ($type == 'entityform' &amp;&amp; !empty($data['entityform'])) {
    $elementform = $data['entityform'];
    foreach ($tokens as $name =&gt; $original) {
      switch ($name) {
        case 'field-foo':
           $replacements[$original] = str_replace('_', '-', $name);
           break;
      }
    }
  }
  return $replacements;
}


The other avenue I was exploring was whether this token needs declaring to Rules via hook_rules_data_info() but I cannot see why so I have not explored it further as the entity form appears to be pushing it through to Rules, just not creating the token so that the email can see it.
I have managed to find a work around using hook_tokens(). Through viewing the $data array, I was able to find the field and write some code which manipulated the incorrect field and created the token correctly for Rules by walking through the field array. 

function MYMODULE_tokens($type, $tokens, array $data = array(), array $options = array()) {
 $replacements = array();
 $sanitize = !empty($options['sanitize']);
  if ($type == 'entityform' &amp;&amp; !empty($data['entityform'])) {
    $elementform = $data['entityform'];
    foreach ($tokens as $name =&gt; $original) {
      switch ($name) {
       case 'field-foo':
         $name = str_replace('-', '_', $name);
         $field = $elementform-&gt;name
         $replacements[$original] = $field[und][0]['value'];
         break;
      }
    }
  }
  return $replacements;
}


I would be happy to learn if there is a better way of achieving this goal in Drupal.