You are here

function shurly_api_key_form in ShURLy 8

Same name and namespace in other branches
  1. 6 shurly_service/shurly_service.module \shurly_api_key_form()
  2. 7 shurly_service/shurly_service.module \shurly_api_key_form()

Form callback; Display a form with a textfield containing a user's API key.

1 string reference to 'shurly_api_key_form'
shurly_service_block_view in shurly_service/shurly_service.module
Implements hook_block_view().

File

shurly_service/shurly_service.module, line 92
Link ShURLy functionalities to services module. @todo add option to rate limit requests @todo add option for user api keys

Code

function shurly_api_key_form($form, &$form_state) {
  $user = \Drupal::currentUser();
  module_load_include('inc', 'shurly_service', 'shurly_api_keys');
  $key = shurly_get_api_key($user->uid);
  $form = [];
  if ($key) {
    $form['key'] = [
      '#type' => 'textfield',
      '#title' => t('API key'),
      '#default_value' => $key,
      '#description' => t('You can provide this key to 3rd party apps rather than sharing your password.'),
    ];
    $form['reset'] = [
      '#type' => 'submit',
      '#value' => t('Reset'),
      '#suffix' => t('If a 3rd party is misusing your API key, you can generate a new one.'),
    ];
  }
  else {
    $form['new'] = [
      '#type' => 'submit',
      '#value' => t('Create'),
      '#suffix' => t('Create an API key to use with 3rd party applications.'),
    ];
  }
  return $form;
}