You are here

function token_custom_list_page in Custom Tokens 7

Same name and namespace in other branches
  1. 7.2 token_custom.admin.inc \token_custom_list_page()

Callback for the token_custom admin list page

Return value

string

1 string reference to 'token_custom_list_page'
token_custom_menu in ./token_custom.module
Implementation of hook_menu().

File

./token_custom.admin.inc, line 14
Page callbacks and admin forms of the token_custom module.

Code

function token_custom_list_page() {

  //check if current user has permissions to add/edit/delete custom tokens
  $add_links = user_access('administer custom tokens');

  //load all out tokens
  $tokens = token_custom_load_multiple();
  $token_info = token_info();
  $variables = array();

  //build the table rows
  foreach ($tokens as $token) {

    //get demo value if token doesn't need external data.
    if (empty($token_info['types'][$token->type]['needs-data'])) {
      $value = token_replace('[' . $token->type . ':' . $token->machine_name . ']');
    }
    else {
      $value = t('Demo value not available');
    }
    $row = array(
      $token->name,
      $token->machine_name,
      $token->type,
      $token->description,
      $value,
    );

    //add the edit/delete links if the user has the right permissions
    if ($add_links) {
      $row[] = l(t('Edit'), 'admin/structure/token-custom/' . $token->machine_name . '/edit') . ' / ' . l(t('Delete'), 'admin/structure/token-custom/' . $token->machine_name . '/delete');
    }
    $variables['rows'][] = $row;
  }
  if (empty($variables['rows'])) {
    $variables['rows'][] = array(
      array(
        'data' => t('No custom tokens available.'),
        'colspan' => array(
          6,
        ),
      ),
    );
  }
  $variables['header'] = array(
    t('Name'),
    t('Machine name'),
    t('Type'),
    t('Description'),
    t('Demo (if available)'),
  );

  //Add extra header cell if edit/delete links were printed.
  if ($add_links) {
    $variables['header'][] = "";
  }
  return theme('table', $variables);
}