You are here

function fb_app_form in Drupal for Facebook 5.2

Same name and namespace in other branches
  1. 5 fb_app.module \fb_app_form()

File

./fb_app.module, line 123
Defines a custom node type that stores a facebook application configuration.

Code

function fb_app_form(&$node, &$param) {

  // Helpful link
  if (!$node->nid) {
    drupal_set_message(t("Before completing this form, <a href=!url>create your application</a> on Facebook.", array(
      '!url' => 'http://www.facebook.com/developers/editapp.php?new',
    )));
  }
  $form = array();
  $type = node_get_types('type', $node);

  // We need to define form elements for the node's title and body.
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#weight' => -5,
    '#description' => t('Identifies the application to site administrators.'),
  );

  // We want the body and filter elements to be adjacent. We could try doing
  // this by setting their weights, but another module might add elements to the
  // form with the same weights and end up between ours. By putting them into a
  // sub-array together, we're able force them to be rendered together.
  $form['body_filter']['body'] = array(
    '#type' => 'textarea',
    '#title' => check_plain($type->body_label),
    '#default_value' => $node->body,
    '#required' => FALSE,
    '#description' => 'A brief description of the application.',
  );
  $form['body_filter']['filter'] = filter_form($node->format);

  // Now we define the form elements specific to our node type.
  $form['fb_app'] = array(
    '#tree' => TRUE,
    '#weight' => -4,
    '#validate' => array(
      'fb_app_validate_fb_app' => array(),
    ),
  );
  $form['fb_app']['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#required' => TRUE,
    '#default_value' => $node->fb_app->label,
    '#description' => t('Used behind the scenes, for naming roles, styles, etc.  Use no spaces or weird characters.<br/>Working with multiple copies of a site (i.e. development, staging, production)?  Use the <strong>same</strong> label for each.  Node id and apikey will change from server to server, but the label remains the same.'),
  );
  $form['fb_app']['apikey'] = array(
    '#type' => 'textfield',
    '#title' => t('API Key'),
    '#required' => TRUE,
    '#default_value' => $node->fb_app->apikey,
    '#description' => t('Facebook will generate this value when you create the application.'),
  );
  $form['fb_app']['secret'] = array(
    '#type' => 'textfield',
    '#title' => t('Secret'),
    '#required' => TRUE,
    '#default_value' => $node->fb_app->secret,
    '#description' => t('Facebook will generate this value when you create the application.'),
  );
  $form['fb_app']['id'] = array(
    '#type' => 'textfield',
    '#title' => t('Facebook App ID'),
    '#required' => FALSE,
    '#default_value' => $node->fb_app->id,
    '#description' => t('To learn this number, visit your app\'s About Page (or other links from Facebook\'s Developer App).  The URL will end in ?id=1234...  Enter the number that follows "?id=" here.'),
  );

  // fb_app_data is a placeholder to make it easier for other module to attach
  // various settings to the node.
  $form['fb_app_data'] = array(
    '#tree' => TRUE,
  );

  // Add our own fields to fb_app_data.  Other modules use hook_form_alter to do this.
  $fb_app_data = fb_app_get_data($node->fb_app);
  $data = $fb_app_data['fb_app'];
  if (!$data) {
    $data = array(
      'set_app_props' => TRUE,
    );
  }

  // defaults
  $form['fb_app_data']['fb_app']['set_app_props'] = array(
    '#type' => 'checkbox',
    '#title' => t('Set Application Properties Automatically'),
    '#description' => t('Automatically update Facebook settings for this application.  Disable to prevent customized settings from being overwritten.'),
    '#default_value' => $data['set_app_props'],
  );
  return $form;
}