You are here

function fb_app_form in Drupal for Facebook 5

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

File

./fb_app.module, line 103
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' => 'Not sure yet how this will be used.',
  );
  $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,
  );
  $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.'),
  );
  $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']['canvas'] = array(
    '#type' => 'textfield',
    '#title' => t('Canvas Page Url Suffix'),
    '#required' => TRUE,
    '#default_value' => $node->fb_app->canvas,
    '#description' => t('Type only the part that comes after "http://apps.facebook.com/"'),
  );
  $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,
  );

  // TODO: move this to another module, or get rid of it entirely.

  /* XXX This needs to be re-thought.  Disabling for now.
    $form['fb_app_blocks'] = array('#tree' => TRUE);
    for ($i = 0; $i < _fb_app_num_blocks(); $i++) {
      $form['fb_app_blocks'][$i]['body'] =
        array('#type' => 'textarea',
              '#title' => t('Block !num', array('!num' => $i+1)),
              '#default_value' => $node->fb_app_blocks[$i]->body,
              '#required' => FALSE,
              '#description' => t('Enter markup to be used as this application\'s navigation.  Typically this is an unordered list of links.'),
        );
      $form['fb_app_blocks'][$i]['format'] = filter_form($node->fb_app_blocks[$i]->format,
                                                         NULL,
                                                         array('fb_app_blocks', $i, 'format'));

    }
    */
  return $form;
}