You are here

function theme_custom_formatters_token_tree in Custom Formatters 6

Provide a 'tree' display of nested tokens.

1 call to theme_custom_formatters_token_tree()
custom_formatters_token_tree in ./custom_formatters.admin.inc
1 theme call to theme_custom_formatters_token_tree()
custom_formatters_formatter_basic_editor_form in ./custom_formatters.admin.inc

File

./custom_formatters.admin.inc, line 812
Contains administration functions for the Custom Formatters module.

Code

function theme_custom_formatters_token_tree($field = NULL, $global_types = FALSE, $click_insert = TRUE) {
  module_load_include('inc', 'token', 'token.pages');
  $info = array();
  $fields = _content_field_types();
  if (!empty($fields) && isset($fields[$field])) {
    $module = $fields[$field]['module'];

    // Build tokens list.
    foreach (_custom_formatters_tokens_list($field) as $module) {
      if (function_exists($function = "{$module}_token_list")) {
        $info = array_merge_recursive($function('field'), $info);
      }
    }
  }
  $info = array_merge($info, token_get_list('node'));

  // Prepend node tokens with 'node-' to prevent namespace conflicts.
  $info['node'] = array_flip($info['node']);
  foreach ($info['node'] as &$token) {
    $token = "node-{$token}";
  }
  $info['node'] = array_flip($info['node']);
  $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']);
}