function services_token_access_user_form in Services Token Access 7
Form callback for the user token management form.
1 string reference to 'services_token_access_user_form'
- services_token_access_menu in ./
services_token_access.module - Implements hook_menu().
File
- ./
services_token_access.inc, line 124 - Include file for the services_token_access module.
Code
function services_token_access_user_form($form, &$form_state, $account) {
// Get the current token if it exists.
if ($token_data = services_token_access_load_by_user($account->uid)) {
$token = $token_data['token'];
$updated = $token_data['updated'];
}
else {
$token = NULL;
}
// Generate the form.
$form = array();
$form['current_token'] = array(
'#type' => 'item',
'#title' => t('Current token'),
'#markup' => $token ? '<code>' . $token . '</code>' : t('None'),
);
// Add the token specific stuff.
if ($token) {
$form['token_age'] = array(
'#type' => 'item',
'#title' => t('Token age'),
'#markup' => format_interval(REQUEST_TIME - $updated),
);
// Warning with checkbox to inform the user before doing risky actions.
$form['warning'] = array(
'#type' => 'item',
'#title' => t('Warning'),
'#markup' => t('Generating or removing tokens may results in issues elsewhere. Make sure that all external systems that uses this token are updated as well, as soon as a new token is generated.'),
);
$form['action_check'] = array(
'#type' => 'checkbox',
'#title' => t('Check this box if you want to remove or regenerate the token.'),
);
// The remove/generate buttons are only shown if the checkbox is checked.
$form['remove_button'] = array(
'#type' => 'submit',
'#value' => t('Remove token'),
'#submit' => array(
'_services_token_access_remove_submit',
),
'#states' => array(
'visible' => array(
'#edit-action-check' => array(
'checked' => TRUE,
),
),
),
);
}
// The generate button is always shown if no token exists.
$form['generate_button'] = array(
'#type' => 'submit',
'#value' => t('Generate new token'),
'#submit' => array(
'_services_token_access_renew_submit',
),
'#states' => array(
'visible' => array(
'#edit-action-check' => array(
'checked' => TRUE,
),
),
),
);
$form['uid'] = array(
'#type' => 'value',
'#value' => $account->uid,
);
return $form;
}