function fb_admin_app_select_form_validate in Drupal for Facebook 7.4
1 string reference to 'fb_admin_app_select_form_validate'
File
- ./
fb.admin.inc, line 1329
Code
function fb_admin_app_select_form_validate($form, &$form_state) {
//dpm(func_get_args(), __FUNCTION__);
extract($form_state['fb']);
// $graph, $all_apps
$values = $form_state['values'];
if (!empty($values['client_id']) && !empty($values['client_id_new'])) {
form_error($form['application']['client_id_new'], t('Select either a local application radio button or paste a remote application ID. Not both.'));
return;
}
// Handle a new ID pasted in.
$token = NULL;
if (!empty($values['client_id_new'])) {
// Probably contains ID, but parse just in case.
list($id, $secret, $token) = _fb_admin_parse_textfield($token);
$client_id = $id;
$key = 'client_id_new';
// to pass into form_set_error.
// TODO: save secret if we just learned one.
if ($secret) {
form_set_error($key, t('Use add application form to paste ID and secret.'));
return;
}
}
else {
$client_id = $values['client_id'];
$key = 'client_id';
}
// Make sure we have accurate information about the app.
if (empty($graph[$client_id])) {
try {
$gdata = fb_graph($client_id, $token);
} catch (exception $e) {
fb_log_exception($e, t('Failed to look up application %id.', array(
'%id' => $client_id,
)));
$gdata = NULL;
}
}
else {
$gdata = $graph[$client_id];
}
// TODO: FQL look up application table to confirm application exists. For now, using namespace.
if (empty($gdata) || empty($gdata['id'])) {
form_set_error($key, t('Failed to look up application id %id.', array(
'%id' => $client_id,
)));
}
else {
// Validation passed. Build array to store in variable.
// Save everything we need about this app.
// Don't save tokens or secrets here.
form_set_value($form['fb_app_data'], array(
'client_id' => $gdata['id'],
'name' => $gdata['name'],
'namespace' => !empty($gdata['namespace']) ? $gdata['namespace'] : NULL,
), $form_state);
}
}