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' => t('Foo'), 'description' => t('Tokens related to the foo widget'), 'needs-data' => 'entityform' ); $info['tokens']['foo']['organisation'] = array ( 'name' => t('Janet'), 'description' => t('Custom foo widget field'), 'type' => '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' && !empty($data['entityform'])) { $elementform = $data['entityform']; foreach ($tokens as $name => $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.