You are here

function fb_admin_add_token_form in Drupal for Facebook 7.4

1 string reference to 'fb_admin_add_token_form'
fb_admin_token_page in ./fb.admin.inc

File

./fb.admin.inc, line 332

Code

function fb_admin_add_token_form($form0, &$form_state, $options = array()) {
  $form_state['fb']['options'] = $options + array(
    // Default options.
    'status' => 0,
  );
  if ($user_token = fb_user_token()) {
    $already_saved = db_query("SELECT count(*) FROM {fb_token} WHERE access_token = :token", array(
      ':token' => $user_token,
    ))
      ->fetchField();
    if (!$already_saved) {
      try {
        $graph = fb_graph_batch(array(
          'me',
          'app',
        ), $user_token);
        $form['user_token'] = array(
          '#type' => 'checkbox',
          '#title' => t('%user via %application', array(
            '%user' => $graph['me']['name'],
            '%application' => $graph['app']['name'],
          )),
          '#return_value' => $user_token,
          '#default_value' => 0,
          '#description' => t('Use your current connection to facebook.'),
        );
        $form_state['fb_user_token'] = array(
          'user_token' => $user_token,
          'graph' => $graph,
        );
      } catch (Exception $e) {

        //
      }
    }
  }

  // Placeholder for values set in validate.
  $form['data'] = array(
    '#tree' => TRUE,
  );
  $form['token'] = array(
    // Use textarea because tokens can be very long.
    '#type' => 'textarea',
    '#rows' => 1,
    '#title' => t('Access token'),
    '#description' => t('Paste a complete access token.  Facebook provides developer tools to <a href=!explore_url target=_blank>create</a> and <a href=!tool_url target=_blank>list</a> tokens.', array(
      '!explore_url' => 'https://developers.facebook.com/tools/explorer',
      '!tool_url' => 'https://developers.facebook.com/tools/access_token',
    )),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add token'),
  );

  // Wrap entire form in a fieldset.
  $form0['wrapper'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add Access Token'),
    //'#description' => t('Add a new token.'),
    'form' => $form,
  );
  return $form0;
}