function webform_tokens_token_info in Webform Tokens 7
Implements hook_token_info().
File
- ./
webform_tokens.module, line 11 - The Webform Tokens module.
Code
function webform_tokens_token_info() {
$types['webform-tokens'] = array(
'name' => t('Webform Tokens-provided data'),
'description' => t('Tokens for Webform submitted data and metadata. The old [webform:] style will work if Webform Rules is not enabled.'),
'needs-data' => 'webform-submission',
);
$tokens = array();
$tokens['meta-label-(Field_Key)'] = array(
'name' => t('Meta: Label of given component'),
'description' => t('The label for the specified component. The easiest way to use this is to insert the <code>val</code> token for the component you want, then change <code>val</code> to <code>meta-label</code>.'),
);
$tokens['meta-nid'] = array(
'name' => t('Meta: Parent webform node ID'),
'description' => t('The Node ID (nid) of the parent webform.'),
'type' => 'node',
);
$tokens['meta-sid'] = array(
'name' => t('Meta: Submission ID'),
'description' => t('The submission\'s ID.'),
);
$tokens['meta-uid'] = array(
'name' => t('Meta: Submitting user\'s ID'),
'description' => t('The submitting user\'s ID.'),
'type' => 'user',
);
$tokens['meta-remote_addr'] = array(
'name' => t('Meta: Submitting user\'s IP address'),
'description' => t('The submitting user\'s IP address.'),
);
$tokens['meta-submitted'] = array(
'name' => t('Meta: Submission date'),
'description' => t('The date the webform was submitted.'),
'type' => 'date',
);
$q = db_select('webform_component');
$q
->join('node', 'node', 'webform_component.nid = node.nid');
$q = $q
->fields('webform_component')
->fields('node', array(
'title',
))
->condition('webform_component.type', array(
'markup',
'pagebreak',
'fieldset',
), 'NOT IN')
->execute();
while ($component = $q
->fetchAssoc()) {
$component_extra = !empty($component['extra']) ? unserialize($component['extra']) : array();
if (!is_array($component_extra)) {
$component_extra = array(
$component_extra,
);
}
// Create token if it does not exists; add this nid if it already exists.
$title = '"' . $component['title'] . '" (' . $component['nid'] . ')';
if (isset($tokens['val-' . $component['form_key']])) {
$tokens['val-' . $component['form_key']]['description'] .= ', ' . $title;
}
else {
$tokens['val-' . $component['form_key']] = array(
'name' => t('Value:') . ' ' . $component['name'],
'description' => t('Available in Webform') . ' ' . $title,
);
}
// Render select options components as chained arrays.
if (!empty($component_extra['items'])) {
$tokens['val-' . $component['form_key']]['type'] = 'array';
}
elseif ($component['type'] === 'date') {
$tokens['val-' . $component['form_key']]['type'] = 'date';
}
}
$type_tokens = array(
'webform-tokens' => $tokens,
);
return array(
'types' => $types,
'tokens' => $type_tokens,
);
}