Created
September 4, 2012 08:12
-
-
Save klaasvw/3618369 to your computer and use it in GitHub Desktop.
Add token support to a form element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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