You are here

function fb_admin_add_token_form_validate in Drupal for Facebook 7.4

File

./fb.admin.inc, line 431

Code

function fb_admin_add_token_form_validate(&$form, &$form_state) {
  extract($form_state['values']);

  // $token, $data, $options
  // Look for ID and Secret
  list($id, $secret, $token) = _fb_admin_parse_textfield($token);
  if ($secret) {

    // Save the secret in serialized data field.
    $data['secret'] = $secret;
    form_set_value($form['wrapper']['form']['data'], $data, $form_state);
  }
  if (!$token) {
    form_set_error('token', t('Could not parse token %token.', array(
      '%token' => $form_state['values']['token'],
    )));
    return;
  }
  if ($token) {
    try {
      $errors = array();
      $result = fb_graph_batch(array(
        'me',
        'app',
      ), $token, array(), $errors);

      // Store result in $form_state for submit handler.
      $form_state['fb'] += $result;
      $form_state['fb']['token'] = $token;

      // trimmed
    } catch (exception $e) {
      $message = t('Access token %token is not valid.', array(
        '%token' => $token,
      ));
      fb_log_exception($e, $message);
      form_set_error('token', $message);
    }

    // If passed an app token, we will have app data, but not user data.
    // If no app data, that's a serious error.
    if (empty($result['app'])) {
      $message = t('Access token %token is not valid.', array(
        '%token' => $token,
      ));
      form_set_error('token', $message);
    }
  }
  if (!$token && !$user_token) {
    form_set_error('token', t('You have not given a token to add.'));
  }
}