You are here

function fb_admin_set_properties_form_submit in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 fb.admin.inc \fb_admin_set_properties_form_submit()

Confirm form submit function. We don't use fb_app_set_app_properties, because fb_app.module may not be enabled.

File

./fb.admin.inc, line 293
Admin pages and forms for Drupal for Facebook.

Code

function fb_admin_set_properties_form_submit($form, &$form_state) {
  $fba_id = $form_state['values']['fba_id'];
  $fb_app = fb_get_app(array(
    'fba_id' => $fba_id,
  ));
  $props = $form['#fb_props'];
  if ($fb_app && count($props)) {
    if ($fb = fb_api_init($fb_app)) {
      try {
        $result = fb_graph($fb_app->id, $props + array(
          'access_token' => fb_get_token($fb),
        ), 'POST', $fb);

        // @todo handle $result != true, if that ever happens.
        // Success.
        $form_state['redirect'] = FB_PATH_ADMIN_APPS . '/' . $fb_app->label;
        drupal_set_message(t('Note that it may take several minutes for property changes to propagate to all facebook servers.'));
        if (fb_verbose()) {
          drupal_set_message(t('Set the following properties for %label application:<br/><pre>!props</pre>', array(
            '%label' => $fb_app->label,
            '!props' => print_r($props, 1),
          )));
          watchdog('fb_app', 'Set facebook app properties for %label.', array(
            '%label' => $fb_app->label,
          ), WATCHDOG_NOTICE, l(t('view apps'), FB_PATH_ADMIN));
        }

        // Allow third-parties to set additional "properties" such as restrictions.  And allow fb_app.module to store application namespace.
        fb_invoke(FB_ADMIN_OP_POST_SET_PROPERTIES, array(
          'fb_app' => $fb_app,
          'fb' => $fb,
          'properties' => $props,
        ), array(), FB_ADMIN_HOOK);
      } catch (Exception $e) {
        drupal_set_message(t('Failed to set the following properties for %label application.  You may need to manually editing remote settings!<br/><pre>!props</pre>', array(
          '%label' => $fb_app->label,
          '!props' => print_r($props, 1),
        )), 'error');
        fb_log_exception($e, t('Failed to set application properties on Facebook'));
      }
    }
  }
}