You are here

function fb_app_edit_form in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 fb_app.admin.inc \fb_app_edit_form()
  2. 6.2 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
Implements hook_menu().

File

./fb_app.admin.inc, line 64

Code

function fb_app_edit_form($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' => $fb_app->label,
    )), 'warning');
    drupal_not_found();
    exit;
  }
  if (!isset($fb_app)) {

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

  // Similar to #node
  if (!$fb_app->label) {
    $helptext = '<ol>
<li>Visit the Facebook application page, <a target="_blank" href="https://developers.facebook.com/apps">https://developers.facebook.com/apps</a>, and click "Create New App".</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 App ID and Application Secret into this form.</li>
</ol>';
    $form['helptext'] = array(
      '#markup' => t($helptext),
      '#weight' => -10,
    );
    $form['helptext2'] = array(
      '#markup' => t('It is recommended to administer drupal in one browser (this one) and log into facebook in another browser, so no cookies are shared.  So for example if using Chrome, follow the create app link above in an incognito window.'),
      '#prefix' => '<p><em>',
      '#suffix' => '</em></p>',
    );
  }
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#required' => TRUE,
    '#maxlength' => 20,
    '#default_value' => $fb_app->label,
    '#maxlength' => 20,
    '#description' => t('A short machine-friendly name for this application.  Use letters and numerals only (no spaces, etc). <br/>Module code may refer to this label, in order to customize the behavior of this app.<br/>When working with multiple copies of an application (i.e. development, staging, production),  use the <strong>same label</strong> on all servers.  Apikey, secret and ID will 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, but you prefer not to delete the settings.'),
  );

  // ID, apikey and secret are shown on facebook.  User copies and pastes values.
  $form['id'] = array(
    '#type' => 'textfield',
    '#title' => t('Facebook App ID'),
    '#required' => TRUE,
    '#default_value' => $fb_app->id,
    '#description' => t('Facebook will generate this value when you create the application.'),
  );
  $form['secret'] = array(
    '#type' => 'textfield',
    '#title' => t('Secret'),
    '#required' => TRUE,
    '#default_value' => isset($fb_app->secret) ? $fb_app->secret : NULL,
    '#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' => isset($data['fb_app']) ? $data['fb_app']['set_app_props'] : NULL,
    '#description' => t('Synchronize Facebook settings for this application when you save this form.  Disable this if you have customized your callback URL, or other settings on facebook.com.  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;
}