You are here

function l10n_client_user in Localization client 6.2

Same name and namespace in other branches
  1. 6 l10n_client.module \l10n_client_user()

Implementation of hook_user().

Set up API key for localization server.

File

./l10n_client.module, line 509
Localization client. Provides on-page translation editing.

Code

function l10n_client_user($type, &$edit, &$account, $category = NULL) {
  if ($type == 'form' && $category == 'account') {
    $items = $form = array();
    if (variable_get('l10n_client_use_server', FALSE) && user_access('submit translations to localization server', $account)) {

      // Build link to retrieve user key.
      $server_link = variable_get('l10n_client_server', 'http://localize.drupal.org') . '?q=translate/remote/userkey/' . l10n_client_user_token($account);
      $items['l10n_client_key'] = array(
        '#type' => 'textfield',
        '#title' => t('Your Localization Server API key'),
        '#default_value' => !empty($account->l10n_client_key) ? $account->l10n_client_key : '',
        '#description' => t('This is a unique key that will allow you to send translations to the remote server. To get your API key go to !server-link.', array(
          '!server-link' => l($server_link, $server_link),
        )),
      );
    }
    if (user_access('use on-page translation', $account)) {

      // Add an item to let the user disable the on-page tool.
      $items['l10n_client_disabled'] = array(
        '#type' => 'checkbox',
        '#title' => t('Hide on-page translation from you'),
        '#default_value' => !empty($account->l10n_client_disabled),
      );
    }
    if (!empty($items)) {

      // Add items in a fieldset wrapper if any items available.
      $form = array(
        'l10n_client' => array(
          '#type' => 'fieldset',
          '#title' => t('Localization client'),
          '#weight' => 1,
          'items' => $items,
        ),
      );
    }
    return $form;
  }
  elseif ($type == 'submit' && $category == 'account' && isset($edit['l10n_client_key'])) {
    $edit['l10n_client_key'] = trim($edit['l10n_client_key']);
  }
}