Skip to content

Instantly share code, notes, and snippets.

@klaasvw
Created September 4, 2012 08:12
Show Gist options
  • Save klaasvw/3618369 to your computer and use it in GitHub Desktop.
Save klaasvw/3618369 to your computer and use it in GitHub Desktop.
Add token support to a form element
<?php
/**
* An example form showing how to use tokens.
*/
function my_token_form($form_state) {
$form = array();
// An example element with a value that accepts tokens.
$form['title_text'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#element_validate' => array('token_element_validate'),
'#token_types' => array('node', 'term'),
'#min_tokens' => 1,
);
// A token tree showing the tokens the user can use.
$form['token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => array('node', 'term'),
'#show_restricted' => TRUE,
);
return $form;
}
/**
* An example of rendering text with tokens.
*/
function my_token_output($text, $node) {
return token_replace($text, array('node' => $node));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment