You are here

function theme_token_tree in Token 6

Same name and namespace in other branches
  1. 7 token.pages.inc \theme_token_tree()

Provide a 'tree' display of nested tokens.

4 theme calls to theme_token_tree()
token_actions_goto_action_form in ./token_actions.module
Form builder; Prepare a form for a tokenized redirect action.
token_actions_message_action_form in ./token_actions.module
Form builder; Prepare a form for a tokenized message action.
token_actions_send_email_action_form in ./token_actions.module
Form builder; Prepare a form for a tokenized e-mail action.
token_help in ./token.module
Implements hook_help().

File

./token.pages.inc, line 48
User page callbacks for the token module.

Code

function theme_token_tree($token_types = array(), $global_types = TRUE, $click_insert = TRUE) {
  if ($token_types == 'all' || !is_array($token_types) || in_array('all', $token_types)) {
    $token_types = array(
      'all',
    );
  }
  elseif ($global_types) {
    $token_types[] = 'global';
  }
  else {
    $global_key = array_search('global', $token_types);
    if ($global_key !== FALSE) {
      unset($token_types[$global_key]);
    }
  }

  // Check for token type validity and sort.
  $token_types = array_unique($token_types);
  $info = token_get_list($token_types);

  //$token_types = array_intersect($token_types, array_keys($info));
  $token_types = array_keys($info);
  sort($token_types);
  $header = array(
    t('Token'),
    t('Description'),
  );
  $rows = array();
  foreach ($token_types as $type) {
    $parent = NULL;
    if (count($token_types) > 1) {
      $rows[] = _token_token_tree_format_row($type, array(), TRUE);
      $parent = $type;
    }
    foreach ($info[$type] as $token => $description) {
      $rows[] = _token_token_tree_format_row("[{$token}]", array(
        'description' => $description,
        'parent' => $parent,
      ));
    }
  }
  if (count($rows)) {
    drupal_add_js(drupal_get_path('module', 'token') . '/jquery.treeTable.js');
    drupal_add_css(drupal_get_path('module', 'token') . '/jquery.treeTable.css');
    drupal_add_js(drupal_get_path('module', 'token') . '/token.js');
    drupal_add_css(drupal_get_path('module', 'token') . '/token.css');
  }
  else {
    $rows[] = array(
      array(
        'data' => t('No tokens available.'),
        'colspan' => 2,
      ),
    );
  }
  $table_options = array(
    'attributes' => array(
      'class' => 'token-tree',
    ),
    'caption' => '',
  );
  if ($click_insert) {
    $table_options['caption'] = t('Click a token to insert it into the field you\'ve last clicked.');
    $table_options['attributes']['class'] .= ' token-click-insert';
  }
  return theme('table', $header, $rows, $table_options['attributes'], $table_options['caption']);
}