/[drupal]/contributions/modules/token/token.dev.inc
ViewVC logotype

Contents of /contributions/modules/token/token.dev.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Sat Jul 11 20:47:34 2009 UTC (4 months, 2 weeks ago) by eaton
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +4 -4 lines
File MIME type: text/x-php
Adding better PHPDoc snippets for files and hook implementations, whitespace and coding standards tweaks, etc.
1 <?php
2 // $Id: token.dev.inc,v 1.2 2009/07/11 18:37:07 eaton Exp $
3
4 function token_test_form(&$form_state) {
5 $form['help'] = array(
6 '#prefix' => '<strong>',
7 '#markup' => t('Enter tokens in this field. Optionally pick a node and/or comment to be added to the replacement context.'),
8 '#prefix' => '</strong>',
9 );
10
11 $sql = "SELECT n.nid, n.title FROM {node} n WHERE n.status = 1 ORDER BY n.created DESC LIMIT 10";
12 $results = db_query($sql);
13 $nodes = array('' => t('-None-'));
14 while ($node = db_fetch_object($results)) {
15 $nodes[$node->nid] = check_plain($node->title);
16 }
17 $form['node'] = array(
18 '#type' => 'select',
19 '#title' => t('Node'),
20 '#options' => $nodes,
21 '#default_value' => empty($form_state['input']['node']) ? '' : $form_state['input']['node'],
22 );
23
24 $sql = "SELECT c.cid, c.subject FROM {comment} c WHERE c.status = 1 ORDER BY c.timestamp DESC LIMIT 10";
25 $results = db_query($sql);
26 $comments = array('' => t('-None-'));
27 while ($comment = db_fetch_object($results)) {
28 $comments[$comment->cid] = check_plain($comment->subject);
29 }
30 $form['comment'] = array(
31 '#type' => 'select',
32 '#title' => t('Comment'),
33 '#options' => $comments,
34 '#default_value' => empty($form_state['input']['comment']) ? '' : $form_state['input']['comment'],
35 );
36
37 $form['text'] = array(
38 '#type' => 'textarea',
39 '#title' => t('Enter your text here.'),
40 '#default_value' => empty($form_state['input']['text']) ? 'Hi, [user:name]. Welcome to [site:name]!' : $form_state['input']['text'],
41 );
42
43 $form['submit'] = array(
44 '#type' => 'submit',
45 '#value' => t('Replace tokens'),
46 );
47
48 if (!empty($form_state['input']['text'])) {
49 $v = $form_state['input'];
50 $data = array();
51 if (!empty($v['node'])) {
52 $data['node'] = node_load($v['node']);
53 }
54
55 if (!empty($v['comment'])) {
56 $data['comment'] = comment_load($v['comment']);
57 }
58
59 $form['results'] = array(
60 '#type' => 'item',
61 '#title' => t('Results'),
62 '#markup' => token_replace($form_state['input']['text'], $data),
63 );
64 }
65
66 return $form;
67 }
68
69 function token_test_form_submit(&$form, &$form_state) {
70 if (!empty($form_state['input'])) {
71 $form_state['redirect'] = FALSE;
72 }
73 }

  ViewVC Help
Powered by ViewVC 1.1.2