You are here

function fb_app_edit_form in Drupal for Facebook 6.2

Same name and namespace in other branches
  1. 6.3 fb_app.admin.inc \fb_app_edit_form()
  2. 7.3 fb_app.admin.inc \fb_app_edit_form()

Builds the form used to edit an application.

This form supports both create and edit.

1 string reference to 'fb_app_edit_form'
fb_app_menu in ./fb_app.module
Implementation of hook_menu().

File

./fb_app.admin.inc, line 44

Code

function fb_app_edit_form($form_state, $fb_app = NULL) {

  // If app is managed by this module, it has fba_id.
  if (isset($fb_app) && !$fb_app->fba_id) {
    drupal_set_message(t('Application %label not found.', array(
      '%label' => $label,
    )), 'warning');
    drupal_not_found();
    exit;
  }
  if (!isset($fb_app)) {

    // Defaults for new app.
    $fb_app = (object) array(
      'label' => NULL,
      'apikey' => NULL,
      'canvas' => NULL,
      'fba_id' => NULL,
      'id' => NULL,
      'status' => 1,
      'data' => serialize(array(
        'fb_app' => array(
          'set_app_props' => TRUE,
        ),
      )),
    );

    //drupal_set_title(t('Create Facebook Application'));
  }
  else {

    //drupal_set_title(t('Edit %label', array('%label' => $fb_app->label)));
  }
  $form['#fb_app'] = $fb_app;

  // Similar to #node

  //$form['#node'] = (object) array('fb_app' => $fb_app);  // deprecated! backward compatibility!
  if (!$fb_app->label) {

    // Helpful link
    // http://wiki.developers.facebook.com/index.php/How_To_Write_A_Good_Connect_Plugin
    $helptext = '<ol>
<li>Visit the Facebook application creation page: <a target="_blank" href="http://www.facebook.com/developers/createapp.php">http://www.facebook.com/developers/createapp.php</a>.</li>
<li>Enter a descriptive name in the Application Name field. Users will see this when signing up for your site.</li>
<li>Accept the Facebook Terms of Service.</li>
<li>If building a Canvas Page App, specify a Canvas Path.</li>
<li>Upload icon and logo images. The icon appears in News Feed stories and the logo appears in the Connect dialog when the user connects with your site.</li>
<li>Click Submit.</li>
<li>Copy the displayed API Key, Application Secret and App ID into this form.</li>
</ol>';
    $form['helptext'] = array(
      '#type' => 'markup',
      '#value' => t($helptext),
      '#weight' => -10,
    );
  }
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#required' => TRUE,
    '#default_value' => $fb_app->label,
    '#description' => t('A short name for this application.  Use letters and numerals only (no spaces, etc). <br/>This label will be used by code to customize the behavior of this app.<br/>Working with multiple copies of a site (i.e. development, staging, production)?  Use the <strong>same label</strong> on all servers!  Apikey, secret and ID usually change from server to server, but <strong>the label remains the same</strong>.'),
  );
  $form['status'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enabled'),
    '#default_value' => $fb_app->status,
    '#description' => t('Uncheck if this server no longer hosts this application.'),
  );

  // ID, apikey and secret are shown on facebook.  User copies and pastes values.
  $form['apikey'] = array(
    '#type' => 'textfield',
    '#title' => t('API Key'),
    '#required' => TRUE,
    '#default_value' => $fb_app->apikey,
    '#description' => t('Facebook will generate this value when you create the application.'),
  );
  $form['secret'] = array(
    '#type' => 'textfield',
    '#title' => t('Secret'),
    '#required' => TRUE,
    '#default_value' => $fb_app->secret,
    '#description' => t('Facebook will generate this value when you create the application.'),
  );
  $form['id'] = array(
    '#type' => 'textfield',
    '#title' => t('Facebook App ID'),
    '#required' => FALSE,
    '#default_value' => $fb_app->id,
    '#description' => t('Facebook will generate this value when you create the application.'),
  );

  // fb_app_data is a placeholder where other modules can attach settings.
  $form['fb_app_data'] = array(
    '#tree' => TRUE,
  );

  // Add our own fields to fb_app_data.  Other modules use hook_form_alter to do this.
  $data = fb_get_app_data($fb_app);
  $form['fb_app_data']['fb_app']['set_app_props'] = array(
    '#type' => 'checkbox',
    '#title' => t('Set Application Properties Automatically'),
    '#default_value' => $data['fb_app']['set_app_props'],
    '#description' => t('Automatically update Facebook settings for this application.  Disable this if you have customized your callback URL, for example.  Also disable if another Drupal instance hosts the same application (i.e. with shared subdomain).'),
  );
  $form['buttons'] = array();
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 5,
    '#submit' => array(
      'fb_app_admin_form_submit',
    ),
  );
  if ($fb_app->fba_id) {
    $form['buttons']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#weight' => 15,
      '#submit' => array(
        'fb_app_admin_form_delete_submit',
      ),
    );
  }
  return $form;
}