You are here

function fb_app_admin_form_submit in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 fb_app.admin.inc \fb_app_admin_form_submit()
  2. 6.2 fb_app.admin.inc \fb_app_admin_form_submit()
1 string reference to 'fb_app_admin_form_submit'
fb_app_edit_form in ./fb_app.admin.inc
Builds the form used to edit an application.

File

./fb_app.admin.inc, line 209

Code

function fb_app_admin_form_submit($form, &$form_state) {
  $fb_app = (object) $form_state['values'];
  $fb_app->data = serialize($fb_app->fb_app_data);

  // Get namespace, name from facebook.
  fb_admin_get_app_info($fb_app);
  $orig_app = $form['#fb_app'];
  if ($orig_app->fba_id) {

    // Updating.
    try {
      db_update('fb_app')
        ->fields(array(
        'label' => $fb_app->label,
        'status' => $fb_app->status,
        'apikey' => $fb_app->id,
        // Note, apikey deprecated.  Using ID.
        'secret' => $fb_app->secret,
        'id' => $fb_app->id,
        // Canvas and title are learned from facebook, not the form.
        'canvas' => !empty($fb_app->namespace) ? $fb_app->namespace : '',
        'title' => !empty($fb_app->name) ? $fb_app->name : $fb_app->label,
        'data' => $fb_app->data,
      ))
        ->condition('fba_id', $orig_app->fba_id)
        ->execute();
      watchdog('fb_app', 'Updated Facebook Application %label.', array(
        '%label' => $fb_app->label,
      ), WATCHDOG_NOTICE, l(t('view apps'), FB_PATH_ADMIN_APPS));
    } catch (Exception $e) {

      // Log the exception to watchdog.
      watchdog_exception('fb_app', $e);
      drupal_set_message(t('Failed to save changes to facebook application %title (%label). Check the log.', array(
        '%label' => $fb_app->label,
        '%title' => $fb_app->name,
      )));
    }
    drupal_set_message(t('Saved changes to Facebook application %title (%label).', array(
      '%title' => $fb_app->name,
      '%label' => $fb_app->label,
    )));

    // Should we just go ahead and flush the cache here automatically?
    drupal_set_message(t('Recommended: <a href=!cache_url>clear cached data</a> after changing Facebook app settings.', array(
      '!cache_url' => url('admin/config/development/performance'),
    )), 'warning');
  }
  else {

    // Inserting.
    try {
      db_insert('fb_app')
        ->fields(array(
        'label' => $fb_app->label,
        'status' => $fb_app->status,
        'apikey' => $fb_app->id,
        // Note, apikey deprecated.  Using ID.
        'secret' => $fb_app->secret,
        'id' => $fb_app->id,
        // Canvas and title are learned from facebook, not the form.
        'canvas' => !empty($fb_app->namespace) ? $fb_app->namespace : '',
        'title' => !empty($fb_app->name) ? $fb_app->name : $fb_app->label,
        'data' => $fb_app->data,
      ))
        ->execute();
      watchdog('fb_app', 'Created Facebook Application %label.', array(
        '%label' => $fb_app->label,
      ), WATCHDOG_NOTICE, l(t('view apps'), FB_PATH_ADMIN_APPS));
      drupal_set_message(t('Created facebook application %title (%label).', array(
        '%label' => $fb_app->label,
        '%title' => $fb_app->name,
      )));
    } catch (Exception $e) {

      // Log the exception to watchdog.
      watchdog_exception('fb_app', $e);
      drupal_set_message(t('Failed to create facebook application %title (%label). Check the log.', array(
        '%label' => $fb_app->label,
        '%title' => $fb_app->name,
      )));
    }
  }
  if ($fb_app->status) {
    fb_app_set_app_properties($fb_app);

    // Set callback URL, etc.
  }
  $form_state['redirect'] = FB_PATH_ADMIN;
}