You are here

function fb_admin_token_generate_validate in Drupal for Facebook 7.4

1 string reference to 'fb_admin_token_generate_validate'
fb_element_info in ./fb.module
Implements hook_element_info().

File

./fb.admin.inc, line 1649

Code

function fb_admin_token_generate_validate($element, &$form_state) {
  $token = NULL;
  if (!empty($element['#value']['fb_admin_token_generate_new'])) {

    // Validate newly generated token.
    $token = $element['#value']['fb_admin_token_generate_new'];
    try {
      $graph = fb_graph_batch(array(
        'me',
        'app',
      ), $token);
      $form_state['fb_graph'] = $graph;
      extract($graph);

      // $me, $app.
      // If there's a new generated token, the URL has params (i.e. 'code' etc) that need to be removed before form is rendered again.
      if (empty($form_state['redirect'])) {
        $form_state['redirect'] = current_path();
      }
    } catch (Exception $e) {
      form_error($element, t('Could not validate new token.  %detail', array(
        '%detail' => $e
          ->getMessage(),
      )));
      $token = NULL;
    }
  }

  // Simplify values for submit handlers.
  form_set_value($element, $token, $form_state);
}