You are here

function theme_token_tree_link in Token 7

Theme a link to a token tree either as a regular link or a dialog.

1 call to theme_token_tree_link()
theme_token_tree in ./token.pages.inc
Provide a 'tree' display of nested tokens.

File

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

Code

function theme_token_tree_link($variables) {
  if (empty($variables['text'])) {
    $variables['text'] = t('Browse available tokens.');
  }
  if (!empty($variables['dialog'])) {
    drupal_add_library('token', 'dialog');
    $variables['options']['attributes']['class'][] = 'token-dialog';
  }
  $info = token_theme();
  $tree_variables = array_intersect_key($variables, $info['token_tree']['variables']);
  $tree_variables = drupal_array_diff_assoc_recursive($tree_variables, $info['token_tree']['variables']);
  if (!isset($variables['options']['query']['options'])) {
    $variables['options']['query']['options'] = array();
  }
  $variables['options']['query']['options'] += $tree_variables;

  // We should never pass the dialog option to theme_token_tree(). It is only
  // used for this function.
  unset($variables['options']['query']['options']['dialog']);

  // Add a security token so that the tree page should only work when used
  // when the dialog link is output with theme('token_tree_link').
  $variables['options']['query']['token'] = drupal_get_token('token-tree:' . serialize($variables['options']['query']['options']));

  // Because PHP converts query strings with arrays into a different syntax on
  // the next request, the options have to be encoded with JSON in the query
  // string so that we can reliably decode it for token comparison.
  $variables['options']['query']['options'] = drupal_json_encode($variables['options']['query']['options']);

  // Set the token tree to open in a separate window.
  $variables['options']['attributes'] + array(
    'target' => '_blank',
  );
  return l($variables['text'], 'token/tree', $variables['options']);
}