You are here

function token_devel_token_object in Token 7

Same name and namespace in other branches
  1. 6 token.pages.inc \token_devel_token_object()

Menu callback; prints the available tokens and values for an object.

1 string reference to 'token_devel_token_object'
token_menu in ./token.module
Implements hook_menu().

File

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

Code

function token_devel_token_object($entity_type, $entity, $token_type = NULL) {
  $header = array(
    t('Token'),
    t('Value'),
  );
  $rows = array();
  $options = array(
    'flat' => TRUE,
    'values' => TRUE,
    'data' => array(
      $entity_type => $entity,
    ),
  );
  if (!isset($token_type)) {
    $token_type = $entity_type;
  }
  $tree = token_build_tree($token_type, $options);
  foreach ($tree as $token => $token_info) {
    if (!empty($token_info['restricted'])) {
      continue;
    }
    if (!isset($token_info['value']) && !empty($token_info['parent']) && !isset($tree[$token_info['parent']]['value'])) {
      continue;
    }
    $row = _token_token_tree_format_row($token, $token_info);
    unset($row['data']['description']);
    unset($row['data']['name']);
    $rows[] = $row;
  }
  $build['tokens'] = array(
    '#theme' => 'tree_table',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => array(
      'class' => array(
        'token-tree',
      ),
    ),
    '#empty' => t('No tokens available.'),
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'token') . '/token.js',
      ),
      'css' => array(
        drupal_get_path('module', 'token') . '/token.css',
      ),
    ),
  );
  return $build;
}