You are here

function fb_admin_application_edit_form in Drupal for Facebook 7.4

Builds the form used to edit an application.

This form supports both create and edit.

3 string references to 'fb_admin_application_edit_form'
fb_enable in ./fb.install
Implements hook_enable().
fb_menu in ./fb.module
Implements hook_menu().
fb_update_7401 in ./fb.install
Upgrade applications from modules/fb 3.x to 4.x.

File

./fb.admin.inc, line 812

Code

function fb_admin_application_edit_form($form, $form_state, $data = NULL) {
  if (is_numeric($data)) {
    $fba = $data;
  }
  elseif (!empty($data['id'])) {
    $fba = $data['id'];
  }
  else {
    $fba = 0;
  }
  if ($fba) {
    $fb_app = db_query("SELECT * FROM {fb_application} WHERE fba = :fba", array(
      ':fba' => $fba,
    ))
      ->fetchAssoc();
  }
  if (empty($fb_app)) {
    $fb_app = array();
  }

  // Defaults for new app.
  $fb_app = $fb_app + array(
    'namespace' => NULL,
    'fba' => NULL,
    'status' => FB_STATUS_APP_ENABLED,
    'data' => NULL,
    'secret' => NULL,
    'title' => t('UNKNOWN'),
  );
  $form['#fb_app'] = $fb_app;

  // Similar to #node
  // ID, apikey and secret are shown on facebook.  User copies and pastes values.
  $form['fba'] = array(
    '#type' => 'textfield',
    '#title' => t('Facebook Application ID'),
    '#required' => TRUE,
    '#default_value' => $fb_app['fba'],
    '#description' => t('Copy and paste <em>App ID</em> (a.k.a. <em>API Key</em>) from <a href=!url target=_blank>Facebook</a>.', array(
      '!url' => 'https://developers.facebook.com/apps',
    )),
  );
  $form['secret'] = array(
    '#type' => 'textfield',
    '#title' => t('Secret'),
    '#required' => FALSE,
    '#default_value' => $fb_app['secret'],
    '#description' => t('For locally hosted applications, copy and paste <em>App Secret</em> from Facebook.'),
  );

  // Placeholders, will be computed during validate.
  $form['data'] = array(
    '#tree' => TRUE,
  );
  $form['fb_app_data'] = array(
    '#type' => 'value',
    '#value' => NULL,
  );
  foreach (array(
    'namespace',
    'title',
    'status',
  ) as $key) {
    $form[$key] = array(
      '#type' => 'value',
      '#value' => $fb_app[$key],
    );
  }
  $default_app = variable_get(FB_VAR_DEFAULT_APP);
  $is_default = !$default_app || $default_app['client_id'] == $fb_app['fba'];
  $form['is_default'] = array(
    '#type' => 'value',
    '#value' => $is_default,
  );
  $form['make_default'] = array(
    '#type' => 'checkbox',
    '#title' => t('Default application'),
    '#description' => t('If your website hosts only one Facebook Application, check this box.  If you host more than one, you may choose one primary application.'),
    '#default_value' => $is_default,
  );
  if (!$is_default) {
    $form['make_default']['#description'] .= '<br/>' . t('If checked, this application will replace %application as the default.', array(
      '%application' => $default_app['name'],
    ));
  }
  $form['states'] = array(
    '#tree' => TRUE,
  );
  $form['states']['enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enabled'),
    '#default_value' => $fb_app['status'] | FB_STATUS_APP_ENABLED,
    '#return_value' => FB_STATUS_APP_ENABLED,
    '#description' => t('Uncheck if this server no longer hosts this application, but you prefer not to delete the settings.'),
  );

  // TODO: add other app states.
  $form['buttons'] = array();
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save application'),
    '#weight' => 20,
  );
  if ($fb_app['fba']) {
    $form['buttons']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete application'),
      '#weight' => 21,
      '#submit' => array(
        'fb_admin_form_delete_submit',
      ),
    );
  }
  return $form;
}