You are here

function token_custom_edit_form in Custom Tokens 6

Same name and namespace in other branches
  1. 5 token_custom.module \token_custom_edit_form()
  2. 7.2 token_custom.admin.inc \token_custom_edit_form()
  3. 7 token_custom.admin.inc \token_custom_edit_form()
1 string reference to 'token_custom_edit_form'
token_custom_menu in ./token_custom.module
Implementation of hook_menu().

File

./token_custom.module, line 228
The Token Custom module.

Code

function token_custom_edit_form(&$form_state, $token_custom = null) {
  if ($token_custom) {
    $form['token_custom_tkid'] = array(
      '#type' => 'value',
      '#value' => $token_custom->tkid,
    );
  }
  $form['token_custom_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Token ID'),
    '#description' => t('Machine name of the token ID. It must start with token_custom_'),
    '#default_value' => $token_custom ? $token_custom->id : 'token_custom_',
    '#required' => TRUE,
  );
  $form['token_custom_description'] = array(
    '#type' => 'textfield',
    '#title' => t('Description'),
    '#description' => t('Description that will appear in the token\'s help.'),
    '#default_value' => $token_custom ? $token_custom->description : NULL,
    '#required' => TRUE,
  );
  $options = array();
  $options['global'] = t('Global');
  $options['node'] = t('Node');
  $options['user'] = t('User');
  $options['taxonomy'] = t('Taxonomy');
  $options['comment'] = t('Comment');
  $form['token_custom_type'] = array(
    '#type' => 'radios',
    '#title' => t('Type'),
    '#description' => t('Select the type of the token you would like to add. Depending on the type you\'ll have access to the specific object in your php code.'),
    '#required' => TRUE,
    '#options' => $options,
    '#default_value' => $token_custom ? $token_custom->type : NULL,
  );
  $form['token_custom_php'] = array(
    '#type' => 'textarea',
    '#title' => t('PHP replacement'),
    '#description' => t('Enter the php code that will be evaluated. You do not need to enclose the code between %php. You have $user, $comment, $node and $taxonomy available depending on the type. You have also the variable $type which the actual type of token. Global has no particular object to use. The code should return a string.', array(
      '%php' => '<?php ?>',
    )),
    '#required' => TRUE,
    '#default_value' => $token_custom ? $token_custom->php : NULL,
    // tell some wysiwyg modules not to enable the editor for this textarea
    '#wysiwyg' => FALSE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  if ($token_custom) {
    $form['delete'] = array(
      '#value' => l(t('Delete'), 'admin/build/tokens/' . $token_custom->tkid . '/delete'),
    );
  }
  return $form;
}