1.20.x system.theme.inc theme_token_tree($variables)

Provide a 'tree' display of nested tokens.

Related topics

File

modules/system/system.theme.inc, line 630
Theme functions for the System module.

Code

function theme_token_tree($variables) {
  $token_types = $variables['token_types'];
  $info = token_get_info();

  if ($token_types == 'all') {
    $token_types = array_keys($info['types']);
  }
  elseif ($variables['global_types']) {
    $token_types = array_merge($token_types, token_get_global_token_types());
  }

  $options = array(
    'flat' => TRUE,
    'restricted' => $variables['show_restricted'],
    'depth' => $variables['recursion_limit'],
  );
  $multiple_token_types = (count($token_types) > 1);
  $rows = array();

  foreach ($info['types'] as $type => $type_info) {
    if (!in_array($type, $token_types)) {
      continue;
    }

    if ($multiple_token_types) {
      $row = _token_token_tree_format_row($type, $type_info, TRUE);
      unset($row['data']['value']);
      $rows[] = $row;
    }

    $tree = token_build_tree($type, $options);
    foreach ($tree as $token => $token_info) {
      if (!empty($token_info['restricted']) && empty($variables['show_restricted'])) {
        continue;
      }
      if (!empty($token_info['deprecated'])) {
        continue;
      }
      if ($multiple_token_types && !isset($token_info['parent'])) {
        $token_info['parent'] = $type;
      }
      $row = _token_token_tree_format_row($token, $token_info);
      unset($row['data']['value']);
      $rows[] = $row;
    }
  }

  $table_variables = array(
    'header' => array(
      t('Name'),
      t('Token'),
    ),
    'rows' => $rows,
    'attributes' => array('class' => array('token-tree')),
    'empty' => t('No tokens available'),
  );

  if ($variables['click_insert']) {
    $table_variables['caption'] = t('Select a token to insert it into the current field.');
    $table_variables['attributes']['class'][] = 'token-click-insert';
  }

  backdrop_add_library('system', 'token');
  $output = theme('tree_table', $table_variables);
  return $output;
}