1 system.theme.inc theme_token_tree_link($variables)

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

File

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

Code

function theme_token_tree_link($variables) {
  if (empty($variables['text'])) {
    $variables['text'] = t('Browse available tokens');
  }

  if (!empty($variables['dialog'])) {
    backdrop_add_library('system', 'token');
    $variables['options']['attributes']['class'][] = 'use-ajax token-browser-link';
  }

  $info = system_theme();
  $tree_variables = array_intersect_key($variables, $info['token_tree']['variables']);
  $tree_variables = backdrop_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'] = backdrop_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'] = backdrop_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']);
}